CF868C:Qualification Rounds(思维)

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 0otherwise.

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


题意:有N个元素,每个元素有K个属性,0或1,判断有无任意一个元素子集,其每个属性的1数量<= 子集的大小/2。

思路:当N>1时,假设存在这样一个子集符合要求,那么肯定存在其中的<=2个元素也能符合要求。证明:对于属性1,从K1=1和K1=0的集合里各取一个数,有(n/2)^2种组合,那么K2最坏的情况能破坏其中的(n/4)^2种组合,K3,K4亦然,那么有(n/2)^2 > 3*((n/4)^2),这里的除法是下取整。所以总能找到2个元素符合要求。题目K<=4,至多有(1<<4)-1种情况,暴力一下就行了。

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;
int vis[1<<4], a[40];
int main()
{
    int n, k, m, cnt=0;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; ++i)
    {
        int num = 0;
        for(int j=0; j<k; ++j)
        {
            scanf("%d",&m);
            num = num<<1|m;
        }
        if(!num) return 0*puts("YES");
        if(++vis[num] == 1) a[cnt++] = num;
    }
    for(int i=0; i<cnt; ++i)
        for(int j=i+1; j<cnt; ++j)
            if((a[i]&a[j]) == 0)
                return 0*puts("YES");
    puts("NO");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值