JAG2015 Wall Making Game

JAG2015 Wall Making Game_第1张图片JAG2015 Wall Making Game_第2张图片

http://dreadnought.icpc-camp.org/2015%20JAG%20Spring

http://jag2015spring.contest.atcoder.jp/assignments(results可查看代码)

#include <stdio.h>
#include <string.h>
char map[22][22];
int n,m, tbl[21][21][21][21];
bool num[21][21][21][21][405];
int back(int r1, int r2, int c1, int c2){
	if(r2<r1 || c2<c1) return 0;
	if(tbl[r1][r2][c1][c2]!= -1) return tbl[r1][r2][c1][c2];
	for(int i=r1;i<=r2;i++){
		for(int j=c1;j<=c2;j++){
			if(map[i][j] == '.'){
				int ret=back(r1,i-1,c1,j-1)^back(r1,i-1,j+1,c2)^back(i+1,r2,j+1,c2)^back(i+1,r2,c1,j-1);
				//printf("%d %d %d %d : %d %d %d\n",r1,r2,c1,c2,i,j,ret);
				num[r1][r2][c1][c2][ret]=1;
			}
		}
	}
 
	for(int i=0;i<=400;i++){
		if(num[r1][r2][c1][c2][i] == 0){ //{r1,c1,r2,c2}达不到这种可能,对手就可以利用这个漏洞在这一块区域获胜
			tbl[r1][r2][c1][c2]=i;
			break;
		}
	}
	return tbl[r1][r2][c1][c2];
}
int main(){
	memset(tbl,-1,sizeof(tbl));
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",map[i]);
 
	int ret=back(0,n-1,0,m-1);
	//printf("%d\n",ret);
	if(ret)
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}


你可能感兴趣的:(JAG2015 Wall Making Game)