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 ...
随机推荐
- GitHub项目管理维护实用教程
GitHub项目维护教程 1)注册GitHub账户并登陆: 2)在Windows cmd(或Ubuntu中的terminal)中cd到自己的工作目录,将仓库clone下来: 命令: git clo ...
- Ubuntu中使用python3中的venv创建虚拟环境
以前不知道Python3中内置了venv模块,一直用的就是virtualenv模块,venv相比virtualenv好用不少,可以替代virtualenv 一.安装venv包: $ sudo apt ...
- Mac查看端口号是否被占用及释放
1.查看使用端口进程 lsof -i: 端口号 2.释放进程 kill 你的PID 3.再次执行第一步,是否无进程占用 lsof -i: 端口号
- DB2部分查询SQL
/* 部分SQL */ --添加主键 alter TABLE TABLE_SCHEMA.TABLE_NAME add constraint PK_TABLE_NAME primary key(COL1 ...
- EffectiveC++
宁可以编译器替换预处理器 define 不被视为语言的一部分,因此也就有可能在预处理阶段被优化掉,导致相关变量出现错误. #define ASPECT_RATIO 1.63 //可以尝试将其替换为 c ...
- LeetCode. 计数质数
题目要求: 统计所有小于非负整数 n 的质数的数量. 示例i: 输入: 10 输出: 4 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 . 代码: class Soluti ...
- dos(cmd)命令大全(本文摘至于网络)
命令简介 cmd是command的缩写.即命令行 . 虽然随着计算机产业的发展,Windows 操作系统的应用越来越广泛,DOS 面临着被淘汰的命运,但是因为它运行安全.稳定,有的用户还在 ...
- 怎样获取Cookie
使用 document.cookie 获取; document.cookie
- LeetCode 腾讯精选50题--合并K个排序链表
今天的题目稍微有点复杂了,因为是K个有序链表的合并,看到这道题后的大体思路是这样的: 1.首先先做到两个链表的合并,链表的合并我想到的是用递归操作, 2.其次是多个链表的合并,所以在第一步实现的基础上 ...
- ONNX预训练模型加载
tvm官网中,对从ONNX预训练模型中加载模型的教程说明 教程来自于:https://docs.tvm.ai/tutorials/frontend/from_onnx.html#sphx-glr-tu ...