您的位置:首页 > 其它

codeforces contest 868 problem C(补集 状压)

2017-10-06 15:17 495 查看
 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 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 and0 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行,每行k个数,选m行使每一位置 的相加个数和 不超过总个数的一半

解:k很小可以状压做 ,不超过一半的本质就是就是他的贡献不超过一半 那么直接让贡献小于等于1 枚举俩个补集就可以了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
set<int>st;

int main()
{
st.clear();
int n, k;
scanf("%d %d", &n, &k);
for(int i=0; i<n; i++)
{
int x=0;
for(int j=0; j<k; j++)
{
int h;
scanf("%d", &h);
x|=(h<<j);
}
st.insert(x);
}
if(*(st.begin())==0)
{
puts("YES");
return 0;
}
for(auto i:st)
{
int now=(i^15);
for(int j=0; j<16; j++)
{
if((j&now)==j)
{
if(st.find(j)!=st.end())
{
puts("YES");
return 0;
}
}
}
}
puts("NO");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: