Codeforces Round #438 C. Qualification Rounds

来源:互联网 发布:北京淘宝美工培训2ds 编辑:程序博客网 时间:2024/05/21 04:16

C. Qualification Rounds
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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!

Input

The first line contains two integers nk (1 ≤ n ≤ 1051 ≤ 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.

Output

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").

Examples
input
5 31 0 11 1 01 0 01 0 01 0 0
output
NO
input
3 21 01 10 1
output
YES
Note

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.


这题我当时没有做,现在补上

队伍数量小于等于四个的时候,如果存在一个题目集合能满足这个条件,那么这个题目集合里必定有两个题目满足这个条件,(一个题目的情况可以特判)why?请听我慢慢道来。

1 先看一个队伍的时候,必然满足条件吧。
2 看两个队伍的时候我们假设第i行第j列上的点是黑点的话第j个队伍就是知道第i个题目的内容的,我们现在假设现在取了2y个题目,两个队伍的时候每列各有y个黑点y个白点,我们假设右边Y个黑点中有a个黑点的左边是黑点,那么还有y-a个黑点左边是白点那么就有a个白点左边是白点,y-a个白点左边是黑点意思是有2*a行是纯色点(a行纯黑a行纯白)2*(y-a)行是间色点(y-a行左黑右白,y-a行左白右黑)那么可以发现,因为y*2>=2,0<=a<=y(只有一个题目的时候特判)那么不管a取什么值,都至少存在有一对题目,要不是纯黑纯白,要不就是左黑右白左白右黑。
1 0
1 0
1 1
1 1
0 1
0 1
0 0
0 0

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呢?就是团队2y行是左黑右白,有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

四个队伍拆成两个队伍和两个队伍的,我们先称这两个队伍为团队1与团队2

团队1和团队2也满足之前所说的条件( 2*a行纯色点(纯黑a行纯白a行),2*(y-a)行间色点(左黑右白y-a行,左白右黑y-a行)0<=a<=y;)假设团队12*a行纯色,团队22*b行纯色,如果都有纯色,即(a>=1&& b>=1)那么就取两个团队中纯白的那行就好了呗,团队1和团队2的纯白不在一行那么就取这两行就好了,如果在一行那么就取这一行,另一行任意取都无所谓。

如果只有一团队1有纯色另一个团队2没有纯色呢,一样的,其中有纯色的团队1取纯白色那行,然后不管团队2是左黑右白还是左白右黑,取另一行团队2的对应色就好了,因为团队1纯白色那行和任意行都可以对应。

最后只有一个情况,就是a==0 && b==0两个团队都没有纯色行咋整

首先我们注意到了,如果两个团队都没有纯色,那么两个团队都必然是y行左白右黑y行左黑右白,我们先取团队1任意一行(比如左白右黑,那么剩下能取还有y行左黑右白的)然而不管这行对应的团队2是左黑右白还是左白右黑剩下只有y-1行与这行完全相同的颜色,团队1剩下可取的y行里有团队2 y-1行的相同色,也绝对还剩下一行绝对不同。至此,证毕

0 0 0 0
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1

0 0 1 0
1 1 0 0
1 0 1 1
0 1 0 1

0 0 1 0
1 1 0 1
1 0 1 0
0 1 0 1

1 0 0 1
1 0 1 0
1 0 1 0
1 0 1 0
0 1 1 0
0 1 0 1
0 1 0 1
0 1 0 1

既然证明了(如果存在一个题目集合能满足这个条件,那么这个题目集合里必定有两个题目满足这个条件)这句话,那么我们只要暴力枚举出两个题目时候所有满足条件的情况,因为K<=4,所以最坏情况也只有3^4中情况,然后直接对输入进行扫描,如果有相同的情况,那么就是Yes否则就是No


#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>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;}



阅读全文
0 0
原创粉丝点击