codeforce868c

来源:互联网 发布:季后赛数据排名 编辑:程序博客网 时间:2024/06/06 03:55

Qualification Rounds

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个队伍。已知这些队伍认识的题目。现在要你定制一个比赛,要求比赛中的题目每个队认识的不能超过一半,问是否可能。

原文章传送门

#include <iostream>#include <fstream>#include <cstdio>#include <cstring>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <cmath>#include <algorithm>#include <functional>#define inf 1000000using namespace std;typedef long long ll;const int MAXN=1e5+10;const int MAX=1e5+10;const double eps=1e-6;int n,k;int vis[20];int main(){    #ifdef ONLINE_JUDGE    #else    freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    #endif    int juge=0;    cin>>n>>k;    for(int i=1;i<=n;i++){        int t,temp=0;        for(int j=1;j<=k;j++){            scanf("%d",&t);            if(t)                temp+=pow(2,j-1);        }        vis[temp]=1;    }    for(int i=0;i<=16;i++){        for(int j=0;j<=16;j++){            if(!(i&j)&&vis[i]&&vis[j])                juge=1;        }    }    if(juge)        cout<<"YES"<<endl;    else        cout<<"NO"<<endl;    return 0;   }
原创粉丝点击