CodeForces 924A

A. Mystical Mosaic
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a rectangular grid of n rows of m initially-white cells each.

Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.

There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that  or , where  denotes intersection of sets, and  denotes the empty set.

You are to determine whether a valid sequence of operations exists that produces a given final grid.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.

Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.

Output

If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).

You can print each character in any case (upper or lower).

Examples
input
Copy
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
output
Yes
input
Copy
5 5
..#..
..#..
#####
..#..
..#..
output
No
input
Copy
5 9
........#
#........
..##.#...
.......#.
....#.#.#
output
No
Note

For the first example, the desired setup can be produced by 3 operations, as is shown below.

For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.

题目大意:现在有n行m列的小格子区域,每次可以选择若干行和若干列,将他们交点处的格子标记,每行每列只能选择一次。现在给你一种状态的格子,问能否通过题目中的操作得到所给情况的格子。

题解:依次比较每横行的格子,如果相等,那么他们可以通过学则同样的列来完成,如果两行不相同,并且两行中在同一列都有“#”,那这种情况下,就会出现至少有一列被重复选择过,这显然是不满足题意的,就一定是"No"了。

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxn = 55;
char grid[maxn][maxn];
int m,n;
int check(int a, int b)
{
    int book = 0;
    for(int i = 0; i<m; i++)
    {
        if(grid[a][i]!=grid[b][i])
        {
            book = 1;
            break;
        }
    }
    if(book==1)
    {
        for(int i = 0; i<m; i++)
        {
            if(grid[a][i] == '#' && grid[b][i] == '#')
            {
                return 1;
            }
        }
    }
    return 0;
}
int main()
{

    scanf("%d%d",&n,&m);
    getchar();
    memset(grid, 0, sizeof(grid));
    int flag = 0;
    for(int i = 0; i<n; i++)
    {
        gets(grid[i]);
    }
    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; j<n; j++)
        {
            flag = check(i,j);
            if(flag == 1)
            {
                printf("No\n");
                return 0;
            }
        }
    }


    if(flag == 0)
    {
        printf("Yes\n");
    }
//    else
//        printf("No\n");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值