CodeForces - 868C Codeforces Round #438 (Div. 1 + Div. 2 ) C题

本文探讨了在编程竞赛中,如何从大量问题中选择合适的子集,确保每个经验丰富的团队只知道所选问题的一半,通过将01排列组合转化为十进制数进行判断,提供了一种有效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qualification Rounds

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


这道题思维还是比较难想的;

首先可以发现,k<=4,这说明最多有24种01排列组合;再观察会发现,只要找到2组01排列组合,它们在相同位的值是不一样的,就一定存在;如果没有找到,那么就肯定不存在;

可以把01排列转化为10进制数,然后直接&判断是否为0就行;

#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
#define lson k<<1
#define rson k<<1|1
#define inf 0x3f3f3f3f
//ios::sync_with_stdio(false);
using namespace std;
const int N=200100;
const int M=1000100;
const ll mod=1e9+7;
bool vis[20];
int main(){
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int a=0;
		for(int j=1;j<=k;j++){
			int x;
			cin>>x;
			a*=2;
			a+=x;		
		}
		vis[a]=true;
	}
	int ok=0;
	for(int i=0;i<=(1<<k);i++){
		if(!vis[i]) continue;
		for(int j=0;j<=(1<<k);j++){
			if(!vis[j]||(i&j)) continue;
			ok=1;
			break;
		}
	}
	if(ok) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值