Codeforces 868C - Qualification Rounds 【状态压缩+暴力枚举】


C. Qualification Rounds


time limit per test  2 seconds

memory limit per test      256 megabytes


Snark and Philip are preparing the problemset for the upcomingpre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select anynon-empty subset of it as a problemset.

k experienced teams are participating inthe contest. Some of these teams already know some of the problems. To make thecontest interesting for them, each of the teams should know at most half of theselected problems.

Determine if Snark and Philip can make an interestingproblemset!

Input

The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number ofproblems 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 aninteresting problemset, and "NO" otherwise.

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

 

【题意】


现在有k支队伍要参加一个比赛,题库中有n道题目,其中有些队伍已经知道了某些题目,现在给出每道题目每支队伍是否知道的情况,问是否存在一套题目使得所有队伍最多只知道一半的题目。


【思路】


首先我们得到一个结论,如果存在满足条件的一套题目,那么其中至少存在两题满足条件(一道题的情况其实一样)。


也就是说,我们只要从题库中找到是否存在两道题满足条件。因为选多了可以,少的一定可以。


但由于n范围比较大,显然无法 n2 枚举,但我们可以注意到k的范围较小,所以想到可以用二进制状态压缩去做。


对于每道题目,我们用二进制位来表示每个队伍对其是否了解的状态,并用一个数组保存。


然后只要 n2 枚举一下所有状态(最多16个状态),先判断是否存在这个状态对应的题目是否存在,若都存在且两个状态的与等于0 即满足条件,因为这样可以保证没有一支队伍同时知道两道题目。


#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n,k;
int vis[(1<<4)+5];

int main()
{
    int x;
    while(~scanf("%d%d",&n,&k))
    {
        mst(vis,0);
        for(int i=1; i<=n; i++)
        {
            int state=0;
            for(int j=1; j<=k; j++)
            {
                scanf("%d",&x);
                state+=(1<<(j-1))*x;
            }
            vis[state]=1;
        }
        int flag=0;
        for(int i=0; i<16; i++)
        {
            for(int j=0; j<16; j++)
            {
                if(vis[i]==0||vis[j]==0) continue;
                if((i&j)==0)
                {
                    flag=1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值