1. 程式人生 > >codeforces 868C Qualification Rounds

codeforces 868C Qualification Rounds

ted other nbsp round ant rep min rst mes

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!

題目大意:

有n個為題,每個問題被一些球隊知道,現能否選出一些問題,使得每個隊知道的問題至多一半

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

ZYYS(賊有意思)

首先經分析發現,最好情況下只要2個就行了

因為假如選了2個不符條件,選了3個符合條件,那麽顯然可以只選其中2個

如果只選2個解決不了,那麽顯然多選也解決不了

把每一個問題的狀態壓縮,枚舉所有狀態,如果(i&j)==0那麽就可以

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 int f[101],n,k,flag;
 7 int main()
 8 {int i,j,x;
 9   cin>>n>>k;
10   for (i=1;i<=n;i++)
11     {
12       int cnt=0;
13       for (j=1;j<=k;j++)
14     {
15       scanf("%d",&x);
16       cnt+=(1<<j-1)*x;
17     }
18       f[cnt]=1;
19     }
20   flag=0;
21   for (i=0;i<16;i++)
22     for (j=0;j<16;j++)
23       if ((i&j)==0&&f[i]&&f[j]) 
24     {
25       flag=1;
26     }
27   if (flag) cout<<"YES\n";
28   else cout<<"NO\n";
29 }

codeforces 868C Qualification Rounds