链接:

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 2871 Memory Control (区间合并 连续段的起始位置 点所属段的左右端点)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2871 题意: 四种操作: 1.Reset  清空所有内存2.New x  分配一个大小为x的内存块返回,返 ...

  2. vue中页面跳转拦截器的实现方法

    首先对index.js的router进行配置; export default new Router({ routes: [ { path: '/consultancy', name: 'consult ...

  3. 【Funny Things】002——鞋的颜色

    网上的那张鞋子的图片到底是什么颜色的?灰绿色还是粉色? 1. 先截取图片中鞋的那块的图片,获取大小 2. 带入大小分别计算R,G,B平均值 3. 通过计算所得的数据画图可得结果 from PIL im ...

  4. Linux下安装jdk中遇到的坑

    比如:我以jdk-8u211-linux-i586.tar.gz为例进行. 下载完成后解压到指定文件下先创建java文件目录,如果已存在就不用创建[root@lyh:] # mkdir -p /usr ...

  5. Python解Leetcode: 725. Split Linked List in Parts

    题目描述:给定一个单链表,写一个函数把它分成k个单链表.分割成的k个单链表中,两两之间长度差不超过1,允许为空.分成的k个链表中,顺序要和原先的保持一致,比如说每个单链表有3个结点,则第一个单链表的结 ...

  6. Linux 网络工具netcat(nc)的应用

    NETCAT netcat是Linux常用的网络工具之一,它能通过TCP和UDP在网络中读写数据,通过与其他工具结合和重定向,可以在脚本中以多种方式使用它. netcat所做的就是在两台电脑之间建立链 ...

  7. Codeforces 1097D. Makoto and a Blackboard

    传送门 首先考虑如果 $n$ 只有一个质因数的情况,即 $n=p^t$ 那么显然可以 $dp$ ,设 $f[i][j]$ 表示第 $i$ 步,当前剩下 $p^j$ 的概率 那么转移很简单: $f[i] ...

  8. Css解决表格超出部分用省略号显示

    小伙伴们有没有的遇到页面显示时,因为数据太长导致显示的表格某一列过长,从而导致页面的不美观,下面我们来看一看如何用Css样式解决表格超出部分用省略号显示的问题. 主要设置两个样式: table{ ta ...

  9. c#Socket通讯

    参考http://bbs.cskin.net/thread-326-1-1.html的大神的代码 socket封装 /// <summary> /// 自定义Socket对象 /// &l ...

  10. vue组件常用传值

    一.使用Props传递数据   在父组件中使用儿子组件 <template> <div> 父组件:{{mny}} <Son1 :mny="mny"&g ...