Description
Given a M×N matrix A. Aij ∈ {0, 1} (0 ≤ i < M, 0 ≤ j < N), could you find some rows that let every cloumn contains and only contains one 1.
状压DP(据说dfs也能过)(话说O(216*m)为啥能过啊???)算了,反正都是枚举。写题解主要是为了一件事,就是要说明什么叫位运算优先级是最后的,比判断语句还后(啊啊啊啊啊!!!)
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
using namespace std;
int c[320],n,m,k1,t;
bool flag;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(c,0,sizeof(c));
flag=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&k1);
c[j]+=(k1<<i-1);
}
}
for(int s=0;s<(1<<n);s++)
{
for(int j=1;j<=m;j++)
{
t=s&c[j];
if(t!=0 && (t&(t-1))==0)//一定不是t&(t-1)==0,他会先计(t-1)==0!!!
{
if(j==m)
flag=1;
else continue;
}
else break;
}
if(flag)
break;
}
if(flag) printf("Yes, I found it\n");
else printf("It is impossible\n");
}
return 0;
}