| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不知为何总是WA,但过了一些样例了,求解释……#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[350],m,n,all[18][320];
bool vis[350];
bool dfs(int sum)
{
if(sum==n)
{
return 1;
}
//cout<<"int"<<endl;
int s=0;
for(int i=0;i<m;i++)
{
if(!vis[i])
{
vis[i]=1;
bool ok=1;
for(int j=0;j<n;j++)
{
if(all[i][j])
{
if(a[j]) ok=0;
a[j]++;
s++;
}
}
if(ok)
{
//cout<<s<<endl;
if(dfs(sum+s)) return 1;
else
{
vis[i]=0;
for(int j=0;j<n;j++)
{
if(all[i][j])
{
a[j]--;
s=0;
}
}
}
}
else
{
vis[i]=0;
for(int j=0;j<n;j++)
{
if(all[i][j])
{
a[j]--;
s=0;
}
}
}
}
}
return 0;
}
int main()
{
while(scanf_s("%d%d",&m,&n)!=EOF)
{
memset(all,0,sizeof(all));
memset(a,0,sizeof(a));
int ru;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
scanf_s("%d",&all[i][j]);
}
}
if(dfs(0)==1) cout<<"Yes, I found it"<<endl;
else cout<<"It is impossible"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator