Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int chess[5][5],n;
- bool ispossible(int i,int j)
- {
- if(chess[i][j]==1 || chess[i][j]==-1) return false;
- int ro,col,x,y;
- for(ro=i+1;ro<n && chess[ro][j]!=-1;ro++)
- {
- if(chess[ro][j]==1)
- return false;
- }
- for(ro=i-1; ro>=0 && chess[ro][j]!=-1; ro=ro-1)
- {
- if(chess[ro][j]==1) return false;
- }
- for(col=j+1; col<n && chess[i][col]!=-1; col++) {
- if(chess[i][col]==1) return false;
- }
- for(col=j-1; col>=0 && chess[i][col]!=-1; col=col-1) {
- if(chess[i][col]==1) return false;
- }
- return true;
- }
- int rook()
- {
- int cnt=0,i,j,res;
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- if(ispossible(i,j)==true)
- { chess[i][j]=1;
- res=1+rook();
- cnt=max(cnt,res);
- chess[i][j]=0;
- }
- }
- }
- return cnt;
- }
- int main()
- {
- while(cin>>n && n)
- {
- string s;
- memset(chess,0,sizeof(chess));
- int i,j;
- for(i=0;i<n;i++)
- {
- cin>>s;
- for(j=0;j<n;j++)
- {
- if(s[j]=='X')
- chess[i][j]=-1;
- }
- }
- int mn= rook();
- cout<<mn<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement