Codeforces-868C

来源:互联网 发布:java中的foreach循环 编辑:程序博客网 时间:2024/06/06 03:13

链接:

  http://codeforces.com/contest/868/problem/C


题目:

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

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.


题意:

  给你n个题目,k个队,1代表这个队伍知道这道题的答案,0代表不知道。问你能否调出若干个题,使得每只队伍知道的答案数目不多于调出来的题目的数目的一半。


思路:

  可以看到k很小,对于每个问题,可以通过每个队伍知不知道这道题的情况来将这类题目唯一化,所以总共有16种可能,用二进制记录一下然后寻找满足题目的情况即可。


实现:

#include <cstdio>int book[27], n, k, tmp, t;int main() {    scanf("%d%d", &n, &k);    while(tmp = 0, n--) {        for(int j=0 ; j<k ; j++) scanf("%d", &t), tmp |= (t<<j);        book[tmp]++;    }    for(int i=0 ; i<16 ; i++) for(int j=0 ; j<16 ; j++) if(i&j == 0 && book[i] && book[j]) return 0*printf("YES\n");    printf("NO\n");    return 0;}