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. Linux入门命令1

    查询及帮助 man查看命令帮助,命令的词典,显示Unix联机参考手册的页面 info从Info参考系统中显示文件 help查看Linux内置命令的帮助,比如cd命令. whatis 为指定命令显示一行 ...

  2. Luogu1501 Tree II - LCT

    Code #include<cstdio> #include<cstring> #include<algorithm> #define rd read() #def ...

  3. Python的程序入口 __name__属性

    python中每个模块都有一个 '__name__' 属性,当其值为 '__main__' 时,表名该模块自身在运行,否则是被引入的. 当一个模块被当做一个整体调用的时候,模块名.__name__ 的 ...

  4. Spring Boot学习笔记:传统maven项目与采用spring boot项目区别

    项目结构区别 传统的maven构建的项目结构如下: 用maven构建的采用springboot项目结构如下: 二者结构一致,区别如下:传统项目如果需要打成war包,需要在WEB-INF目录结构配置we ...

  5. Maven手动将jar包放入本地仓库

    mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面 ...

  6. centos 7 安装svn客户端

    rpm -qa subversion yum remove -y subversion yum install -y subversion svnserve --version svn checkou ...

  7. php 制作验证码不显示的问题

    php制作验证码的代码,这里就不多说了,网上有很多的,这里说一些可能遇到的问题. 1. 首先是检查自己的php.ini文件,是否支持gd库. 2.保证代码没有出问题. 3.检查字体文件路径是否正确. ...

  8. 2018.10.23 hdu2476String painter(区间dp)

    传送门 一道挺妙的区间dp. 我们先用区间dp求出第一个串为空串时的最小代价. 然后再加入原本的字符更新答案就行了. 代码: #include<bits/stdc++.h> using n ...

  9. android 应用商店

    下面更多 http://wiki.youmi.net/Wiki/PromotionChannelIDs 小米 http://market.xiaomi.com/dev安智市场 http://dev.a ...

  10. (5)How to let go of being a "good" person — and become a better person

    https://www.ted.com/talks/dolly_chugh_how_to_let_go_of_being_a_good_person_and_become_a_better_perso ...