Codeforces Round #438 (Div. 1 + Div. 2 combined) C. Qualification Rounds

本文探讨了如何从一系列题目中筛选出合适的子集,确保每支参赛队伍最多只了解所选题目的一半,以保持比赛的趣味性和挑战性。文章提出了一种解决方案,通过状态压缩的方式枚举所有可能的组合,最终验证是否存在符合条件的题集。

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

C. Qualification Rounds

Problem Statement

    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

Example 1
    Input
        5 3
        1 0 1
        1 1 0
        1 0 0
        1 0 0
        1 0 0
    Output
        NO
Example 2
    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,表示有n道题和k支队伍。之后给出一张表格,第i行第j列若为1表示第j个队伍知道第i个题目,为0则表示不知道,问你是否能选出一套题(任意多),来满足任何一支队伍最多只知道其中一半的题目。

思路

    首先我们可以知道,所有能选出题目集合的方法中,都可以转化为只有两道题而所有队伍最多只知道一道,又因为k很小,只有4,所以我们可以2424通过状压枚举一下就行了..

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
inline void readLong(ll &x) {
    x=0;int f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x*=f;
}
/*================Header Template==============*/
int cnt[17],x,t,n,k;
int main() {
    readInt(n);
    readInt(k);
    for(int i=1;i<=n;i++) {
        t=0;
        for(int j=1;j<=k;j++) {
            readInt(x);
            t=(t<<1)|x;
        }
        cnt[t]++;
    }
    for(int i=0;i<16;i++)
        for(int j=0;j<16;j++)
            if(cnt[i]&&cnt[j]&&(i&j)==0) {
                puts("YES");
                return 0;
            }
    puts("NO");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值