Codeforces Round #589 (Div. 2) B. Filling the Grid
链接:
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的更多相关文章
- Codeforces Round #589 (Div. 2) Another Filling the Grid (dp)
题意:问有多少种组合方法让每一行每一列最小值都是1 思路:我们可以以行为转移的状态 附加一维限制还有多少列最小值大于1 这样我们就可以不重不漏的按照状态转移 但是复杂度确实不大行(减了两个常数卡过去的 ...
- 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\) ...
- Codeforces Round #589 (Div. 2)
目录 Contest Info Solutions A. Distinct Digits B. Filling the Grid C. Primes and Multiplication D. Com ...
- Codeforces Round #589 (Div. 2) (e、f没写)
https://codeforces.com/contest/1228/problem/A A. Distinct Digits 超级简单嘻嘻,给你一个l和r然后寻找一个数,这个数要满足的条件是它的每 ...
- 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 ...
- 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 ...
- Codeforces Round 589 (Div. 2) 题解
Is that a kind of fetishism? No, he is objectively a god. 见识了一把 Mcdic 究竟出题有多神. (虽然感觉还是吹过头了) 开了场 Virt ...
- Codeforces Round #589 (Div. 2) D. Complete Tripartite(染色)
链接: https://codeforces.com/contest/1228/problem/D 题意: You have a simple undirected graph consisting ...
- Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)
链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...
随机推荐
- ES-实战
一.环境准备 操作系统:mac 依赖的软件:JDK1.8.Postman.NodeJs6.0以上.Maven.Idea ES下载:Elastic官方网站: http://www.elastic.co ...
- Idea中maven的设置
File->setting 输入MAVEN 看到右侧设置情况 Maven home directory 熟路本地moven 仓库目录:D:/springboot/apach ...
- HTTP协议探究(一):缓存
一 复习与目标 1 复习 序章主要用WrieShark抓包HTTP报文 复习了TCP协议 讲述了TCP协议与HTTP之间的关系 HTTP1.1更新原因:HTTP1.0一次TCP连接只能发送一次HTTP ...
- 检索 COM 类工厂中 CLSID 为 {13C28AD0-F195-4319-B7D7-A1BDAA329FB8} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
上午前客户突然来电说换了台电脑重新装的程序不能正常用,发来错误提示如图: 这错误显然不是程序错误,异常写的很清楚 ,COM组件没注册,搜一下CLSID, 原来是GridReport++ ,参考地址: ...
- 排查RabbitMQ安装错误
1.注册表中是否有 HKEY_LOCAL_MACHINE\SOFTWARE\Ericsson\Erlang\ErlSrv\1.1\RabbitMQ 此项.(须有) 2.安装目录是否存在中文.(不可有 ...
- 一步一步搭建 .net core 应用
前言 近段时间 .net core 大火,公司也打算趁此机会把后续项目迁移到 .net core 平台上,我们下面的一帮人也就跟着大部队,开始狂补 dotnetcore 相关的技术了.此贴主要记录我在 ...
- 07 Redis存储Session
django-redis-sessions 官方文档:https://pypi.org/project/django-redis-sessions/ dango-redis 官方文档:http://n ...
- ES6复制数组
ES6复制数组和合并数组 一.复制数组与合并数组 复制数组:它是复合数据类型,直接复制只是复制了指向底层数据结构的指针,而不是复制一个全新的数组 <!DOCTYPE html> <h ...
- eureka解析hostname为localhost问题 (转)
https://blog.csdn.net/liufei198613/article/details/79583686 公司的springcloud已经上线运行,但是最近测试环境老是会出现一个诡异的问 ...
- Phoenix的jdbc封装
一.Phoenix版本 <dependency> <groupId>org.apache.phoenix</groupId> <artifactId>p ...