Codeforces Round #438 C. Qualification Rounds

$###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

input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
output
NO
input
3 2
1 0
1 1
0 1
output
YES

题目大意

有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 16
int 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值