链接:

https://codeforces.com/contest/1228/problem/B

题意:

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).

思路:

枚举每个位置的情况, 挨个乘起来即可.

代码:

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7; int r[1100], c[1100];
int h, w; bool Check(int x, int y, int op)
{
if (y == 1 && r[x] == 0 && op == 1)
return false;
if (x == 1 && c[y] == 0 && op == 1)
return false;
if (y == r[x]+1 && op == 1)
return false;
if (x == c[y]+1 && op == 1)
return false;
if (y <= r[x] && op == 0)
return false;
if (x <= c[y] && op == 0)
return false;
return true;
} int main()
{
cin >> h >> w;
for (int i = 1;i <= h;i++)
cin >> r[i];
for (int i = 1;i <= w;i++)
cin >> c[i];
int res = 1;
for (int i = 1;i <= h;i++)
{
for (int j = 1;j <= w;j++)
{
int tmp = 0;
if (Check(i, j, 0))
tmp++;
if (Check(i, j, 1))
tmp++;
// cout << i << ' ' << j << ' ' << tmp << endl;
res = (res*tmp)%MOD;
}
}
printf("%d\n", res); return 0;
}

Codeforces Round #589 (Div. 2) B. Filling the Grid的更多相关文章

  1. Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)

    题意:问有多少种组合方法让每一行每一列最小值都是1 思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...

  2. Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理

    Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...

  3. Codeforces Round #589 (Div. 2)

    目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...

  4. Codeforces Round #589 (Div. 2) (e、f没写)

    https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...

  5. Codeforces Round #589 (Div. 2) E. Another Filling the Grid(DP, 组合数学)

    链接: https://codeforces.com/contest/1228/problem/E 题意: You have n×n square grid and an integer k. Put ...

  6. Codeforces Round #566 (Div. 2) A. Filling Shapes

    链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...

  7. Codeforces Round 589 (Div. 2) 题解

    Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...

  8. Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)

    链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...

  9. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

随机推荐

  1. [转帖]龙芯服务器部署WEB服务的体验和详细步骤

    龙芯服务器部署WEB服务的体验和详细步骤 2019年01月02日 18:40:34 weixin_40065369 阅读数 1733   版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权 ...

  2. IPv4-构造超网

    5台PC和两个路由器 PC  设置  IP地址     子网掩码    默认网关 路由器设置    接口的IP地址  子网掩码     static(网络   掩码  下一跳) PC1  ping  ...

  3. Java:关于子类继承父类接口时,由于权限没有设定的更广,出错的一个小tip

    今天在写笔记的时候,写的地方出现了小叉叉错号. 发现问题: 这里出错了!原因是因为在子类覆写父类的方法的时候,权限不能开的比父类更低! 加了public后,纠错成功. 由于接口类型下的方法默认都是pu ...

  4. thinkphp5中的raw的作用

    模板中输出变量 默认不展示HTMl 使用raw将其中的中的HTMl内容展示出来 <div class="content"> <div class="co ...

  5. Ubuntu 提示sudo: java: command not found解决办法

    ubuntu下运行sudo Java 时提示“sudo: java: command not found”.在网上找了,其中很多方法都提示要修改/etc/profile的配置,或是修改/etc/env ...

  6. php操作string的函数

    函数库来源于:http://www.w3school.com.cn/php/php_ref_string.asp 我常用的 echo()------------输出一个或多个字符串. 如:echo ' ...

  7. Apache开启.htaccess 支持

    (1) <Directory "${SRVROOT}/htdocs"> # # Possible values for the Options directive ar ...

  8. MVC授权不通过之后不执行任何自定义ActionFilter

    如下一个Action [Authorize] [F1]//自定义过滤器,继承自ActionFilter public ActionResult Index() { return View(); } 如 ...

  9. WindowsAPI操作串口

    #include <windows.h> #include <stdio.h> int main() { //1.打开串口 HANDLE hCom; hCom = Create ...

  10. script标签所应放的位置

    一般放置的位置:<head>标签内,<body>标签内,<body>标签后(建议放在body标签后,利于页面的优化,优化页面结构加载的速度) 1.<head& ...