http://acm.hdu.edu.cn/showproblem.php?pid=1760
dfs + 博弈
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
using namespace std;
//#pragma comment(linker,"/STACK:1000000000,1000000000")
#define LL long long
const int N=55;
char a[N][N];
int n,m;
int dfs()
{/*
for(int i=0;i<n;++i)
{
for(int j=0;j<m;++j)
cout<<a[i][j]<<" ";
cout<<endl;
}*/
int k=0;
for(int i=1;i<n;++i)
{
for(int j=0;j<m-1;++j)
{
if(a[i][j]=='1'||a[i-1][j]=='1'||a[i][j+1]=='1'||a[i-1][j+1]=='1')
continue;
a[i][j]='1';a[i-1][j]='1';a[i][j+1]='1';a[i-1][j+1]='1';
if(dfs()==0)
k=1;
a[i][j]='0';a[i-1][j]='0';a[i][j+1]='0';a[i-1][j+1]='0';
if(k)
break;
}
if(k)
break;
}
return k;
}
int main()
{
//freopen("data.txt","r",stdin);
while(scanf("%d %d",&n,&m)!=EOF)
{
getchar();
for(int i=0;i<n;++i)
{
gets(a[i]);
}
if(dfs())
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
浙公网安备 33010602011771号