// // main.cpp // 639 // // Created by Fangpin on 15/3/9. // Copyright (c) 2015年 FangPin. All rights reserved. // #include <iostream> #include <cstring> #include <cstdio> #include <string> using namespace std; int map[7][7]; int ans,n; void dfs(int x,int y,int sum){ if(!map[x][y]){ ++y; if(y==n+1) {y=1;++x;} if(x<=n) dfs(x,y,sum); } else{ int c1=0,c2=0,i=x,j=y; while(map[i][j]){ if(map[i][j]==2) ++c1; ++i; } i=x;j=y; while(map[i][j]){ if(map[i][j]==2) ++c1; --i; } i=x;j=y; while(map[i][j]){ if(map[i][j]==2) ++c2; ++j; } i=x;j=y; while(map[i][j]){ if(map[i][j]==2) ++c2; --j; } if(c1 || c2){ ++y; if(y==n+1) {y=1;++x;} if(x<=n) dfs(x,y,sum); } else{ ++sum; ans=max(ans,sum); int i=x,j=y; ++y; if(y==n+1) {y=1;++x;} if(x<=n){ map[i][j]=2; dfs(x,y,sum); --sum; map[i][j]=1; dfs(x,y,sum); } } } } int main(int argc, const char * argv[]) { // insert code here... while(scanf("%d",&n),n){ memset(map,0,sizeof(map)); string s; for(int i=1;i<=n;++i){ cin>>s; for(int j=0;j<s.size();++j){ if(s[j]=='.') map[i][j+1]=1; else map[i][j+1]=0; } } ans=0; dfs(1,1,0); printf("%d\n",ans); } return 0; }
原文地址:http://blog.csdn.net/fangpinlei/article/details/44156815