链接:

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. 最长回文 HDU - 3068(马拉车算法)

    Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input 输入 ...

  2. thinkphp5.1路由设置小计

    route下定义路由路径,如果是这种情况 'product'=>'home/product/index',//产品信息首页 'product/list'=>'home/product/li ...

  3. Python基础 第四章 字典(1)

    通过名称来访问其各个值的数据结构,映射(mapping). 字典,是Python中唯一的内置映射类型,其中的值不按顺序排列,而是存储在键下.(键,可能是数.字符串.元组). 1.1 字典由 键 及其相 ...

  4. Python 闭包、迭代器、生成器、装饰器

    Python 闭包.迭代器.生成器.装饰器 一.闭包 闭包:闭包就是内层函数对外层函数局部变量的引用. def func(): a = "哈哈" def func2(): prin ...

  5. JVM描述符标识字符含义

    标识字符 含义 B byte C char D double F float I int J long S short Z boolean V void L 对象类型,如Ljava/lang/Obje ...

  6. 安装HAXM报错:failed to configure driver unknown error. failed to open driver 并提示数字签证不可用

    1.安装微软补丁:https://www.microsoft.com/en-us/download/confirmation.aspx?id=46148 2.重启后重新安装HAXM

  7. MyEclipse Derby 这么玩

    首先得把MYECLIPSE自带的JDK的DERBY数据库的JAR文件给导入工程,反正没事把几个都导进来,如下: derby.jar,derbyclient.jar,derbynet.jar,derby ...

  8. Ubuntu/centos/redhat/SUSE sipp安装(带rtp支持,3.5.1版本)

    1.ubuntu 12.04 apt-get install ncurses-dev apt-get install libpcap-dev ./configure --with-pcap make ...

  9. 使用 function 构造函数创建组件和使用 class 关键字创建组件

    使用 function 构造函数创建组件: 如果想要把组件放到页面中,可以把构造函数的名称,当作 组件的名称,以 HTML标签形式引入页面中, 因为在React中,构造函数就是一个最基本的组件. 注意 ...

  10. 较新版FlowPortal BPM不能回车登录

    在BPM安装目录中找到路径:WEB\YZSoft\Login\2018\js\login.js 加回车登录代码如下 //回车登录 $('.yz-input.yzglyph.uid').bind('ke ...