Codeforces Round #438 C. Qualification Rounds

Source: Internet
Author: User
Tags rounds

$###Description
Snark and Philip is preparing the Problemset for the upcoming pre-qualification round for Semi-quarter-finals. They has a bank of n problems, and they want to select any non-empty subset of it as a problemset.

K experienced teams is participating in the contest. Some of these teams already know Some of the problems. The contest interesting for them, each of the teams should know at the most half of the selected problems.

Determine if Snark and Philip can make an interesting problemset! Input

The first line contains 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 was possible to make an interesting problemset, and "NO" otherwise.

You can print each character either upper-or lowercase ("yes" and "yes" were valid when the answer was "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
Main Topic

There are n questions, K team, 1 for the right already know the content, 0 representatives do not know. Ask whether any part of the N test questions can be selected to meet the maximum number of questions per team that is not more than half. Thinking of solving problems

Consider each team's knowledge of each question as a state into a binary, save with integers and mark occurrences. Then in [0, (1<<k−1)] [0, (1 traversal), if the state exists and with another state is equal to 0, then the two states can satisfy the test instructions, directly output "YES". Code Implementation

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <
Cmath> #include <vector> using namespace std;
#define MAXN int A[MAXN];
    int main () {int n,k;
    int t,mi,z;
        while (~SCANF ("%d%d", &n,&k)) {memset (a,0,sizeof (a));
            for (int i=0; i<n; i++) {t=0,mi=1<< (k-1);
                for (int j=0; j<k; J + +) {scanf ("%d", &z);
                T+=z*mi;
            mi/=2;
        } a[t]++;
        } bool Flag=false; for (int i=0; i< (1<<k), i++) {if (a[i]!=0) {for (int j=0; j< (1& LT;&LT;K);
                        J + +) {if (a[j]!=0&& ((i&j) ==0)) {
                        Flag=true;
                        printf ("yes\n");
                    Break }
                }
            }
            if (flag) break;
    } if (!flag) printf ("no\n");
} return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.