Codeforces Round #438 C. Qualification Rounds

来源:互联网 发布:淘宝十元包邮专区在哪 编辑:程序博客网 时间:2024/05/16 08:02

$###Description
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, 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 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.

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

input5 31 0 11 1 01 0 01 0 01 0 0outputNOinput3 21 01 10 1outputYES

题目大意

有n个试题,k个队,1代表该对已经知道该题内容,0代表不知道。问从n个试题中任意抽取一部分,是否可以满足每个队最多只能知道不超过一半的试题。

解题思路

将每个队对于每份试题的了解情况看成一种状态转化为二进制,用整数保存并标记出现次数。然后在[0,(1<<k1)]遍历,若该状态存在并且与另一种状态取与等于0,则这两种状态便可满足题意,直接输出”YES”。

代码实现

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define maxn 16int a[maxn];int main(){    int n,k;    int t,mi,z;    while(~scanf("%d %d",&n,&k))    {        memset(a,0,sizeof(a));        for(int i=0; i<n; i++)        {            t=0,mi=1<<(k-1);            for(int j=0; j<k; j++)            {                scanf("%d",&z);                t+=z*mi;                mi/=2;            }            a[t]++;        }        bool flag=false;        for(int i=0; i<(1<<k); i++)        {            if(a[i]!=0)            {                for(int j=0; j<(1<<k); j++)                {                    if(a[j]!=0&&((i&j)==0))                    {                        flag=true;                        printf("YES\n");                        break;                    }                }            }            if(flag) break;        }        if(!flag)            printf("NO\n");    }    return 0;}
阅读全文
1 0
原创粉丝点击