C. Qualification Rounds
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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!

Input

The first line contains two integers nk (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
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
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个题,m个人,从n个题中挑k道题,使m个人每个人会的题目数不超过k/2。

输入的意思是:第i行第j列为1,说明第j个人会第i道题,为0说明不会

结论:k直接取2就行   取大了反倒不好满足

首先我们先分成两种情况

k = 1       就看有没有全0行嘛,对吧

k >= 2      首先考虑p道题满足的情况下的,首先p道题我们就确定这已经是一个稳定的系统了,那么我们再加一行,这一行肯定有至少一个1(否则这道题全是0,就是第一种情况了),p加一行的话肯定某一个人会多对一道题,意思就是,其它人的正确率会下降,但是不会导致p+1这个集合变得不符合题意,但是加1的那一列却有可能导致集合不符合题意。

所以,直接取k = 2即可,在k=2上面加题反倒可能会使集合可能坏掉

其次说一下具体实现,一共就最多4个人,一道题,最多也就是2的4次方,16种排列。直接枚举每一种即可,

用一个ans[16]表示每种情况出现过几次,在输入的时候就能够处理

附上代码

#include <iostream>
using namespace std;
int arr[16] = {0};
int main()
{
int n,m,i,j,t,temp;
cin >> n >> m;
for(i = 0; i < n; ++i)
{
temp = 0;
for(j = 0; j < m; ++j)
{
scanf("%d",&t);
temp |= t<<j;
}
arr[temp]++;
}
for(i = 0;i < 16; ++i)
{
for(j = 0; j < 16; ++j)
{
if((i&j) == 0 && arr[i] && arr[j])
{
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
}

codeforce868c的更多相关文章

随机推荐

  1. C# json解析字符串总是多出双引号

    json好久没用了,今天在用到json的时候,发现对字符串做解析的时候总是多出双引号. 代码如下: string jsonText = "{'name':'test','phone':'18 ...

  2. poj 2492(关系并查集) 同性恋

    题目;http://poj.org/problem?id=2492 卧槽很前卫的题意啊,感觉节操都碎了, t组测试数据,然后n,m,n条虫子,然后m行,每行两个数代表a和b有性行为(默认既然能这样就代 ...

  3. spring boot (一): Hello World

    什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...

  4. BZOJ1228或洛谷2148 [SDOI2009]E&D

    BZOJ原题链接 洛谷原题链接 完全不会呀.. 写了这题才知道\(SG\)函数原来也能打表找规律... 题解请看大佬的博客 #include<cstdio> using namespace ...

  5. BZOJ 3329 - Xorequ - 数位DP, 矩乘

    Solution 发现 $x \ xor \  2x = 3x$ 仅当 $x$ 的二进制中没有相邻的 $1$ 对于第一个问题就可以进行数位DP 了. 但是对于第二个问题, 我们只能通过递推 打表 来算 ...

  6. PostThreadMessage

    PostThreadMessage是一个Windows API函数.其功能是将一个队列消息放入(寄送)到指定线程的消息队列里,不等待线程处理消息就返回.

  7. Java 算法(一)贪心算法

    Java 算法(一)贪心算法 数据结构与算法目录(https://www.cnblogs.com/binarylei/p/10115867.html) 一.贪心算法 什么是贪心算法?是指在对问题进行求 ...

  8. jsp页面错误的全局处理

    网上搜索spring mvc项目全局异常处理: 大致可以找到两种方案 : 方案1: ExceptionHandlerResolver . spring 提供了两种默认实现,当然你也可以自己实现.. 方 ...

  9. ros 编程习惯

    1.设置ros的info,warning,debug,error等编写的时候要思考,何时该使用,以及在开头要使用设置rosconsole的级别来对应输出,以方便调试. 2.在使用ros_info等的时 ...

  10. codeforces C. Functions again

    题意:给定了一个公式,让你找到一对(l,r),求解出公式给定的F值. 当时没有想到,我把(-1)^(i-l)看成(-1)^i,然后思路就完全错了.其实这道题是个简单的dp+最长连续子序列. O(n)求 ...