Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 4
- char tab[MAX][MAX];
- void leerTab(char tab[MAX][MAX], int tam){
- int i,j;
- for(i=0;i<tam;i++)
- for(j=0;j<tam;j++){
- int car;
- scanf(" %c",&tab[i][j]);
- }
- }
- int max(int value1, int value2){
- if (value1>value2) return value1;
- return value2;
- }
- void buscaPo(int fil, int col,int tam,int* sx, int *sy){
- *sx = fil+1;
- *sy = col;
- if (*sx == tam){
- *sx = 0;
- *sy = col+1;
- }
- }
- int isSafe(int fil, int col,char tab[MAX][MAX], int tam){
- int i;
- if (tab[fil][col] == 'X' || tab[fil][col] == 'T')
- return 0;
- for(i=col-1;i>=0;i--){
- if (tab[fil][i] == 'X') break;
- if (tab[fil][i] == 'T') return 0;
- }
- for(i=fil-1;i>=0;i--){
- if (tab[i][col] == 'X') break;
- if (tab[i][col] == 'T') return 0;
- }
- return 1;
- }
- void llena(int fil,int col,int tam, char tab[MAX][MAX],int *ntorres,int *maxi){
- if (col == tam){
- *maxi = max(*ntorres,*maxi);
- return;
- }
- int sig_x,sig_y;
- buscaPo(fil,col,tam,&sig_x,&sig_y);
- if ( isSafe(fil,col,tab,tam) ){
- tab[fil][col] = 'T';
- (*ntorres)++;
- llena(sig_x,sig_y,tam,tab,ntorres,maxi);
- tab[fil][col] = '.';
- (*ntorres)--;
- }
- llena(sig_x,sig_y,tam,tab,ntorres,maxi);
- }
- int main(int argc, char** argv) {
- int tam;
- while ( scanf("%d",&tam) != EOF){
- if (tam > 0){
- leerTab(tab,tam);
- int torres = 0, mtorres = 0;
- llena(0,0,tam,tab,&torres,&mtorres);
- printf("%d\n",mtorres);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement