Codeforces Round #438 C. Qualification Rounds

來源:互聯網
上載者:User

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

input5 31 0 11 1 01 0 01 0 01 0 0outputNOinput3 21 01 10 1outputYES
題目大意

有n個試題,k個隊,1代表該對已經知道該題內容,0代表不知道。問從n個試題中任意抽取一部分,是否可以滿足每個隊最多隻能知道不超過一半的試題。 解題思路

將每個隊對於每份試題的瞭解情況看成一種狀態轉化為二進位,用整數儲存並標記出現次數。然後在 [0,(1<<k−1)] [0,(1遍曆,若該狀態存在並且與另一種狀態取與等於0,則這兩種狀態便可滿足題意,直接輸出”YES”。 代碼實現

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define maxn 16int 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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.