Codeforces Round #438 C. Qualification Rounds

时间:2022-02-25 08:37:14

Description

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!

解题报告:

猜一个结论:如果存在答案,那么一定存在只由两个问题组成的problemset的解,所以枚举一个串,另一个串用桶判断即可

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=1e5+5,K=6;
int t[3][3][3][3],f[6],n,k;int map[N][K];bool flag=false;
void dfs(int x,int dep){
if(dep==k+1){
if(t[f[1]][f[2]][f[3]][f[4]])flag=true;
return ;
}
if(flag)return ;
if(map[x][dep])f[dep]=false,dfs(x,dep+1);
else{
f[dep]=true;dfs(x,dep+1);
f[dep]=false;dfs(x,dep+1);
}
}
void work()
{
cin>>n>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
scanf("%d",&map[i][j]);
}
t[map[i][1]][map[i][2]][map[i][3]][map[i][4]]++;
}
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++){
flag=false;
dfs(i,1);
if(flag){
puts("YES");
return ;
}
}
puts("NO");
} int main()
{
work();
return 0;
}