Codeforces 868C Qualification Rounds【思维】

来源:互联网 发布:上海 现代建筑 知乎 编辑:程序博客网 时间:2024/05/21 05:06

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 31 0 11 1 01 0 01 0 01 0 0
output
NO
input
3 21 01 10 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.


题目大意:


让我们找出一个非空子集,使得子集中每个位子上的1的数字加和数量小于等于子集大小的一半。‘


思路:


①我们选择的题目数量多少其实对结果的影响并不大,我们问题其实只要选1个题或者两个题就能够完成目标的话,没必要选更多的题目来给大家做
②所以问题就是在找一道题或者两道题来满足题意要求
③找一道题很简单,必须都是0
④如果选两道题的话,那么使得这两道题每一位子上的数加和小于等于1就行了
那么我们O(n)枚举一道题,然后O(16)枚举另外一道题,然后寻找是否存在即可
总时间复杂度O(16*n)

当然我们也可以再优化一手,时间复杂度达到O(16*16)【四位二进制枚举】


Ac代码:


#include<stdio.h>#include<string.h>using namespace std;int vis[2][2][2][2];int b[150000][5];int Slove(int a,int b,int c,int d){    for(int i=0;i<2;i++)    {        for(int j=0;j<2;j++)        {            for(int k=0;k<2;k++)            {                for(int l=0;l<2;l++)                {                    if(vis[i][j][k][l]>0)                    {                        if(a+i<=1&&b+j<=1&&c+k<=1&&d+l<=1)return 1;                    }                }            }        }    }    return 0;}int main(){    int n,k;    while(~scanf("%d%d",&n,&k))    {        int flag=0;        memset(vis,0,sizeof(vis));        for(int i=1;i<=n;i++)        {            int a[5];            int temp=0;            memset(a,0,sizeof(a));            for(int j=0;j<k;j++)            {                scanf("%d",&a[j]);                if(a[j]!=0)temp=1;            }            if(temp==0)flag=1;            vis[a[0]][a[1]][a[2]][a[3]]++;            b[i][0]=a[0];            b[i][1]=a[1];            b[i][2]=a[2];            b[i][3]=a[3];        }        for(int i=1;i<=n;i++)        {            if(Slove(b[i][0],b[i][1],b[i][2],b[i][3])==1)flag=1;        }        if(flag==1)printf("YES\n");        else printf("NO\n");    }}





原创粉丝点击