Codeforces 868C.Qualification Rounds(位运算)

http://codeforces.com/problemset/problem/868/C
C. Qualification Rounds

time limit per test 2 seconds

memory limit per test 256 megabytes

Snark and Philip are preparing the problemset for the upcomingpre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select anynon-empty subset of it as a problemset.

k experienced teams are participating inthe contest. Some of these teams already know some of the problems. To make thecontest interesting for them, each of the teams should know at most half of theselected problems.

Determine if Snark and Philip can make an interestingproblemset!

Input

The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number ofproblems 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 aninteresting problemset, and “NO” otherwise.

Youcan 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

核心:题意转化为存在这样的2道题 &运算结果=0 代表所有人不都会2道题

#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cctype>
using namespace std;

#define PI acos(-1.0)
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++) 
#define rep(i,a,n)  for(int i=a;i<n;i++)
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
const int mod=1e9+7;

int gcd(int a,int b)
{
	return b!=0?gcd(b,a%b):a;

}
int vis[20];
int main()
{
	int n,k,x;//n=1e5 k=4 n,k相差大 状压dp 
	cin>>n>>k;
	for(int i=1;i<=n;i++)//每一道题情况 属于2进制16种状态哪种 
	{
		int state=0;
		for(int j=1;j<=k;j++)
		{
			cin>>x; 
			state+=(1<<(j-1))*x;//个 十 百从左到右 对称的&运算不影响 
		}
		vis[state]=1;
	}
	int flag=0;
	for(int i=0;i<16;i++)	//2进制 
	{
		for(int j=0;j<16;j++)
		{
			if(vis[i]!=0 && vis[j]!=0)//此状态存在 存在2道题 &=0 2道题所有人不都会 
			{
				if((i&j)==0)//优先级 关系 > &|
				{
				 	flag=1;
					break; 
				}
			}
		}
		if(flag)
			break;
	}
	if(flag)
		puts("YES");
	else
		puts("NO");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值