• codeforce 985B Switches and Lamps(暴力+思维)


    Switches and Lamps
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix aconsisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.

    Initially all m lamps are turned off.

    Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards.

    It is guaranteed that if you push all n switches then all m lamps will be turned on.

    Your think that you have too many switches and you would like to ignore one of them.

    Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.

    The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.

    It is guaranteed that if you press all n switches all m lamps will be turned on.

    Output

    Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.

    Examples
    input
    Copy
    4 5
    10101
    01000
    00111
    10000
    output
    Copy
    YES
    input
    Copy
    4 5
    10100
    01000
    00110
    00101
    output
    Copy
    NO

    #include <iostream>
    #include<cstring>
    #include<string>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<deque>
    #include<vector>
    #define ll long long
    #define inf 0x3f3f3f3f
    #define mod 1000000007;
    using namespace std;
    int a[2015][2015];
    int s[2015];
    int main()
    {
        int n,m;
        cin>>n>>m;
        char b[2015];
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            cin>>b;
            for(int j=1;j<=m;j++)
            {
                a[i][j]=b[j-1]-'0';
                s[j]+=a[i][j];
            }
        }
        bool f=0;
        int j;
        for(int i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[j]-a[i][j]==0) break;
            }
            if(j==m+1) f=1;
    
        }
        if(f) cout<<"YES";
        else cout<<"NO";
        return 0;
    }
  • 相关阅读:
    CSU 1605 数独
    HDU 1426 dancing links解决数独问题
    FZU 1686 dlx重复覆盖
    hdu 2295 dlx重复覆盖+二分答案
    zju 3209 dancing links 求取最小行数
    hust 1017 dancing links 精确覆盖模板题
    POJ 1724 二维费用最短路
    【转载】学习总结:初等数论(3)——原根、指标及其应用
    【poj3415-Common Substrings】sam子串计数
    【hdu4436/LA6387-str2int】sam处理不同子串
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270991.html
Copyright © 2020-2023  润新知