codeforces 868c(二进制)

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 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分别代表题目数和队伍数,接下来n行每行k个数代表每道题每个队伍是否知道,判断能否找到这样的情况选出其中几题,每队都只知道至多一半的题。

思路:如果能选出几题满足,那么必定可以选出2题的情况满足。这样使用2进制表示每道题几个队伍的知道情况,这样这道题的情况就变成了一个小于16的数,知道找到两道题的情况&运算为0即可。

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool data[16];
int main()
{
	int n,k;
	int x;
	while(~scanf("%d%d",&n,&k))
	{
		for(int i=0;i<n;i++)
		{
			int cnt=0;
			for(int j=0;j<k;j++)
			{
				scanf("%d",&x);
				cnt*=2;
				cnt+=x;
			}
			data[cnt]=1;
		}
		bool flag=false;
		for(int i=0;i<16;i++)
		{
			int j;
			for(j=0;j<16;j++)
			{
				if(((i&j)==0)&&data[i]&&data[j])
				{
					flag=true;
					break;
				}
			}
			if(j<16)break;
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值