Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of nproblems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
5 3 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0
NO
3 2 1 0 1 1 0 1
YES
In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems.
这题我当时没有做,现在补上
3 三支队伍的时候,我们把它们拆成两个队伍(团队2)和一个队伍(团队1),团队2的情况已经证明过了,2*a行纯色点(纯黑a行纯白a行),2*(y-a)行间色点(左黑右白y-a行,左白右黑y-a行)0<=a<=y;如果我们有纯白的一行点,就是a>=1;我们就取这行点,因为在团队2的情况下,这行和任意一行都是可以搭配的,及满足条件,所以不管对应的团队1是黑点白点,取另一行相反颜色的点就好了。因为一列有y个黑点y个白点,所以必然存在。
那么现在如果a==0呢?就是团队2有y行是左黑右白,有y行是左白右黑我们先任意取一行,假设这行左黑右白(左白右黑也一样)那么能和它对应的左白右黑的行有y行,然后不管我们取的这行对应团队1是什么颜色,所有的行中剩下的同色的个数只剩y-1个,所以就算对应团队二的y行里有y-1行同色,那也还剩一行是绝对不同色的,所以三个队伍也满足这个条件。
1 0 0
1 1 1
0 0 1
0 1 0
1 0 1
1 1 0
0 1 0
0 0 1
4 四个队伍拆成两个队伍和两个队伍的,我们先称这两个队伍为团队1与团队2;
团队1和团队2也满足之前所说的条件( 2*a行纯色点(纯黑a行纯白a行),2*(y-a)行间色点(左黑右白y-a行,左白右黑y-a行)0<=a<=y;)假设团队1有2*a行纯色,团队2有2*b行纯色,如果都有纯色,即(a>=1&& b>=1)那么就取两个团队中纯白的那行就好了呗,团队1和团队2的纯白不在一行那么就取这两行就好了,如果在一行那么就取这一行,另一行任意取都无所谓。
如果只有一团队1有纯色另一个团队2没有纯色呢,一样的,其中有纯色的团队1取纯白色那行,然后不管团队2是左黑右白还是左白右黑,取另一行团队2的对应色就好了,因为团队1纯白色那行和任意行都可以对应。
最后只有一个情况,就是a==0 && b==0两个团队都没有纯色行咋整
#include
#include
#include
#include
using namespace std;
int a[16]={0};
int main() {
int n,k,x;
scanf("%d%d",&n,&k);
for (int i=1; i<=n; i++) {
int s=0;
for(int j=1;j<=k;j++)
{
scanf("%d",&x);
s=s*2+x;
}
a[s]++;
}
bool f=false;
for(int i=0;i<=int(pow(2,k))-1;i++)
{
if(a[i]>0)
for (int j=0; j<=int(pow(2, k))-1; j++) {
if(a[j]>0)
{
if((i&j)==0)
f=true;
}
}
}
if (f) {
printf("YES\n");
}
else
printf("NO\n");
// insert code here...
//std::cout << "Hello, World!\n";
return 0;
}