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
4 5
10101
01000
00111
10000
output
YES
input
4 5
10100
01000
00110
00101
output
NO

Description

给你 n 个开关和 m 个灯。 第 i 个开关打开某一些灯。 该信息以矩阵形式(n 行 m 列),如果第 i 个开关能打开第 j 个灯,则 a ij = 1,如果不能打开则 a ij = 0
 
最初,所有 m 灯都关闭。
 
开关状态仅能从“关”变为“开”。 这意味着如果两个或更多开关连接到同一个灯,那么在任何一个开关被按下后,灯将会开启,并且即使连接到这个灯的任何其他开关被按下,它也将保持开启。
 
保证如果你打开所有 n 个开关,那么所有的 m 个灯都将打开。
 
你的任务就是找出是否存在这样一个开关,如果你忽略(不使用)它,而是按下所有其他的n-1个开关,那么所有的m个灯都将打开。

Input

输入的第一行包含两个整数 n 和 m(1 ≤ n, m ≤ 2000) - 开关的数量和灯的数量。
 
以下n行每行包含m个字符。 如果第i个开关打开第j个灯,则字符 a ij 等于 '1',否则等于 '0'。
 
保证如果你按下所有 n 个开关,所有 m 个灯都将被打开。

Output

如果有一个开关,如果你忽略它并按下所有其他的n - 1开关,所有的m灯都将打开,输出“YES”, 如果没有这样的开关,输出“NO”。

Sample Input

Input

4 5
10101
01000
00111
10000

Output

YES

Input

4 5
10100
01000
00110
00101

Output

NO

解题思路:有n个开关,m盏灯,也就是邻接矩阵的行所代表的是开关,即为第i个开关控制第j盏灯,先求出每一列之和,即每一盏灯控制它的开关数,
然后对每一个开关遍历,如果去掉开关,能控制这一盏灯的开关数为0,则说明该开关并不是多余的并不能取掉,若是不影响则说明可以取掉
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n,m,flag,i,j;
char x[];
int a[][];
int sum[];
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
scanf("%d%d",&n,&m);
getchar();
for(i=; i<=n; i++)
{
gets(x);
for(j=; j<=m; j++)
{
a[i][j]=x[j-]-'';
if(a[i][j]==)
{
sum[j]++;//每一列之和
}
}
}
flag=;
for(i=; i<=n; i++)//行
{
for(j=; j<=m; j++)//列
{
if(sum[j]-a[i][j]==)//对于每一列来说去掉这一行会变成0,说明会有灯不受控制
{
break;
}
}
if(j==m+)//找到一个一个开关不用也不会使灯受影响的
{
flag=;
}
}
if(flag)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return ;
}

Switches and Lamps(思维)的更多相关文章

  1. CF985B Switches and Lamps 思维 第十九

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

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

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

  3. B. Switches and Lamps

    链接 [https://codeforces.com/contest/985/problem/B] 题意 给你n,m,分别是n个开关,m个灯 给一个n*m的字符矩阵aij=1,表示i可以控制j这个灯 ...

  4. codeforces 985B Switches and Lamps

    题意: 有n个开关,m盏灯. 一个开关可以控制多个灯,一旦一个灯开了之后,之后再对这个灯的操作就没用了. 问是否存在一个开关,去掉了这个开关之后,按下其它开关之后所有的灯还是亮的. 思路: 首先统计每 ...

  5. CF985B Switches and Lamps【矩阵操作/枚举】

    [链接]CF985B [题意]:给n盏灯,m个开关,每次按开关只能将灯从灯灭的状态转变为灯亮,问是否存在不按所有开关就将所有灯打开的方法. [分析]:有两种办法,一种代码复杂点,容易想到枚举去掉每一行 ...

  6. HDU 2828 DLX搜索

    Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  7. Educational Codeforces Round 44 (Rated for Div. 2)

    题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...

  8. HDOJ 2828 Lamp DLX反复覆盖

    DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  9. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

随机推荐

  1. SQL Server公用表达式CET递归查询所有上级数据

    with cte as( select bianma,fjbm from #tree where chkDisabled='true' union all select t.bianma,t.fjbm ...

  2. IDEA中使用单元测试@Test等,提示没有 Junit.jar包

    1.File-->Project Structure-->Modules-->右侧Dependencies-->+号-->JARs or directories... 2 ...

  3. Thinkphp5 使用composer中seeder播种机

    前因: 前几天,客户要求做一个会员问答的系统,我就按流程做了,到了需要调用数据库数据时,觉得一个个添加又有点笨~ 解决过程: 后来查了查手册,看看国外blog案例,我搞出来了个不错的方法~~~ 我的使 ...

  4. Java性能优化的50个细节

    在JAVA程序中,性能问题的大部分原因并不在于JAVA语言,而是程序本身.养成良好的编码习惯非常重要,能够显著地提升程序性能. 1. 尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时 ...

  5. excel 开头 结尾,中间 类似 SQL like ab% ,%ab ,%ab%

    excel  开头 结尾,中间  类似 SQL like 'ab%'  ,'%ab'  ,'%ab%' 在R2 单元格  查找   ab开头,ab结尾 =Search("ab",R ...

  6. 一、linux基本操作

    1.linux界面的切换 DOS界面终端打开:Ctrl+Alt+F1  /F2/F3   退出:Ctrl+Alt+F7 终端的打开与退出 打开:Ctrl+Alt+t   退出:Ctrl+d 2.第一次 ...

  7. python3 练习题100例 (四)

    题目四:输入某年某月某日,判断这一天是这一年的第几天? #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 题目四:输入 ...

  8. Java学习笔记十六:Java中的构造方法

    Java中的构造方法 1.使用new+构造方法 创建一个新的对象: 2.构造方法是定义在Java类中的一个用来初始化对象的方法: 3.构造方法与类同名且没有返回值: 4.语法格式: public 构造 ...

  9. php7+apache2.4+mysql 环境配置(window环境)

    最近,小主从事PHP开发.特将最近如何搭建php7的过程记录在此!希望有需要,可以借鉴!( 电脑必须win7 sp1以上, .netframework4 ) Windows7安装php7,Win7+p ...

  10. 推荐 的FPGA设计经验(4) 时钟和寄存器控制架构特性使用

    Use Clock and Register-Control Architectural Features FPGAs provide device-wide clocks and register ...