PersonalCorpus 版 (精华区)
39486 2002-10-07 13:50:20 Accepted
1002 C++ 00:00.00 380K Big Guava
static int p[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char map[6][6];
int n,tot,best;
void tryit(int a, int b)
{
int i,j,k,m;
char savemap[6][6];
i=a; j=b;
while (i<=n) {
if (map[i][j]=='.') {
tot++;
memcpy(savemap,map,sizeof(map));
map[i][j]='o';
for (k=0;k<4;k++) {
m=1;
while (map[i+p[k][0]*m][j+p[k][1]*m]!='X') {
map[i+p[k][0]*m][j+p[k][1]*m]='o';
m++;
}
}
tryit(i+j/n,j%n+1);
tot--;
memcpy(map,savemap,sizeof(map));
}
i+=j/n;
j=j%n+1;
}
if (tot>best) best=tot;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\zju\\i1002","r",stdin);
freopen("c:\\0acm\\zju\\o1002","w",stdout);
#endif
int i,j,k;
char s[10];
while (1) {
scanf("%d\n",&n);
if (n==0) break;
memset(map,'X',sizeof(map));
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++) map[i][j]=getchar();
gets(s);
}
tot=best=0;
tryit(1,1);
printf("%d\n",best);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.082毫秒