codeforces 868C.Qualification Rounds(bitmasks与状压dp)
来源:互联网 发布:网络配线架多少钱 编辑:程序博客网 时间:2024/05/11 02:21
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!
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 0otherwise.
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").
5 31 0 11 1 01 0 01 0 01 0 0
NO
3 21 01 10 1
YES
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行代表1-n个问题,一行有k个数字,对应位置代表那个队伍这题会不会,会是1,不会是0.要求每个队伍至少要会一半题目,问你输入是否满足条件?
思路:
k最多为4,也就是16种状态,按照要求输入之后,利用i&j位运算判断是否互补即可,有就直接输出yes,否则结束循环输出no。
代码:
#include <bits/stdc++.h>using namespace std;int n,k,cnt[16],x;int main(){ scanf("%d%d",&n,&k); for (int i=1;i<=n;++i) { int t=0; for (int j=1;j<=k;++j) { scanf("%d",&x); t=(t<<1)+x; } cnt[t]++; } for (int i=0;i<16;++i) for (int j=i;j<16;++j) if (cnt[i] && cnt[j] && ((i&j)==0)) return puts("YES"),0; puts("NO"); return 0;}
- codeforces 868C.Qualification Rounds(bitmasks与状压dp)
- Codeforces 868 C Qualification Rounds
- codeforces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- CodeForces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868 C. Qualification Rounds (技巧)
- Codeforces 868C Qualification Rounds【思维】
- Codeforces 868C Qualification Rounds 结论
- Codeforces round438 C. Qualification Rounds
- Codeforces Round #438 C 868C Qualification Rounds(思维,非状压dp)
- Codeforces Round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 二进制
- codeforces round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 题解
- Codeforces Round #438 C. Qualification Rounds
- 宗教信仰
- java提高篇(四)-----抽象类与接口
- Qt快捷键
- C++ 字符串
- vue中v-model和value的区别
- codeforces 868C.Qualification Rounds(bitmasks与状压dp)
- iOS日志-把项目storyboard中自带viewController删除后黑屏问题
- NOIP2007 初赛赛后总结
- 给你的博客做个自定义404页面
- 项目实践——redis的服务器和集群的搭建
- 030 高阶导数求导之推导归纳法、公式法
- 深入理解Java的接口和抽象类
- 时间差 two
- Java线程池ThreadPoolExecutor使用和分析(二)