Filling the Grid

传送门
Suppose there is a h×w grid consisting of empty or full cells. Let’s make some definitions:

ri is the number of consecutive full cells connected to the left side in the i-th row (1≤i≤h). In particular, ri=0 if the leftmost cell of the i-th row is empty.
cj is the number of consecutive full cells connected to the top end in the j-th column (1≤j≤w). In particular, cj=0 if the topmost cell of the j-th column is empty.
In other words, the i-th row starts exactly with ri full cells. Similarly, the j-th column starts exactly with cj full cells.在这里插入图片描述
These are the r and c values of some 3×4 grid. Black cells are full and white cells are empty.
You have values of r and c. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of r and c. Since the answer can be very large, find the answer modulo 1000000007(109+7). In other words, find the remainder after division of the answer by 1000000007(109+7).
Input
The first line contains two integers h and w (1≤h,w≤103) — the height and width of the grid.

The second line contains h integers r1,r2,…,rh (0≤ri≤w) — the values of r.

The third line contains w integers c1,c2,…,cw (0≤cj≤h) — the values of c.

Output
Print the answer modulo 1000000007(109+7).

题目大意,判断在输入的图中可以在添加多少点,而不改变输入数据原装;
思路 遍历图,判断是否合法,同时要判断输入的数据是否合法

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int maxn = 1e3+100;
int main()
{
    int h ,w;
    int r[maxn];
    int c[maxn];
    long long ans = 1;
    cin >>h >> w;
    for(int i=0;i<h;i++)cin >> r[i];
    for(int i=0;i<w;i++)cin >> c[i];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(i==c[j]&&j<r[i]){cout <<"0"<<endl;return 0;}
            if(j==r[i]&&i<c[j]){cout <<"0"<<endl;return 0;}
            if(i>c[j]&&j>r[i]){ans*=2;ans%=mod;}
        }
    }
    cout << ans <<endl;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值