- 玩诈欺的小杉
- 2013-11-26 21:11:59 @
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,x,result=0;
int goal[30],num[30];
char end[30][30];
int mi[22]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,
8192,16384,32768,65536,131072,262144,524288,1048576,2097152};
void init()
{
scanf("%d %d %d",&n,&m,&x);
}
void dfs(int i,int j)
{
int flag=0,cp;
if(j==m+1)
return;
num[i-2]=num[i-2]^mi[j];
num[i-1]=num[i-1]^mi[j];
num[i]=num[i]^mi[j];
num[i+2]=num[i+2]^mi[j];
num[i+1]=num[i+1]^mi[j];
num[i]=num[i]^mi[j-1];
num[i]=num[i]^mi[j+1];
if(i!=n+1)
dfs(i+1,j);
if(i==n+1)
dfs(2,j+1);
if((i==(n+1))&&(j==m))
{
for(cp=2;cp<=n+1;cp++)
if((num[cp]|(1+mi[m+1]))!=goal[cp])
{
flag=1;
break;
}
if(flag==0)
result++;
}
flag=0;
num[i-2]=num[i-2]^mi[j];
num[i-1]=num[i-1]^mi[j];
num[i]=num[i]^mi[j];
num[i+2]=num[i+2]^mi[j];
num[i+1]=num[i+1]^mi[j];
num[i]=num[i]^mi[j-1];
num[i]=num[i]^mi[j+1];
if(i!=n+1)
dfs(i+1,j);
if(i==n+1)
dfs(2,j+1);
if((i==(n+1))&&(j==m))
{
for(cp=2;cp<=n+1;cp++)
if((num[cp]|(1+mi[m+1]))!=goal[cp])
{
flag=1;
break;
}
if(flag==0)
result++;
}
}
void deal()
{
int i,j;
char t;
memset(goal,0,sizeof(goal));
memset(num,0,sizeof(num));
for(i=2;i<=n+1;i++)
goal[i]=1+mi[m+1];
for(i=2;i<=n+1;i++)
{
scanf("%c",&t);
for(j=1;j<=m;j++)
{
scanf("%c",&end[i][j]);
if(end[i][j]=='1')
goal[i]+=mi[j];
}
}
dfs(2,1);
}
void solve()
{
int i;
char t;
for(i=1;i<=x;i++)
{
deal();
printf("%d\n",result);
result=0;
scanf("%c",&t);
}
}
int main()
{
init();
solve();
return(0);
}
1 条评论
-
twd2 LV 9 MOD @ 2013-11-26 21:18:42
TLE为Time Exceeded不通过:程序运行时间超过了题目限制
- 1