链接:

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;
}

最新文章

  1. 如何直接在ftp里编辑文件
  2. UART接口基本知识
  3. 【原创】kafka controller源代码分析(二)
  4. MyKTV项目总结
  5. vimdiff
  6. mysql的1045解决方法
  7. java虚拟机涉及内存溢出
  8. ZRender源码分析6:Shape对象详解之路径
  9. [TroubleShooting]&amp;#39;trn\bak&amp;#39; is incorrectly formed. SQL Server cannot process this media family.
  10. C语言之函数的声明
  11. java8-lambda常用语法示例
  12. Python打包方法——Pyinstaller (转)
  13. C# CefSharp 可监听请求等
  14. Mysql 用户 创建与删除(基础1)
  15. Dell R730服务器 Raid5配置
  16. 查看 共享内存 的命令 ipcrm、ipcs
  17. docker默认ip查询
  18. java框架----&gt;quartz的使用(一)
  19. numpy、pandas、scipy介绍
  20. 【洛谷】NOIP提高组模拟赛Day1【组合数学】【贪心+背包】【网络流判断是否满流以及流量方案】

热门文章

  1. [转帖] 飞腾FT2000+ CPU的进展(2019.6)
  2. Websocket基础梳理
  3. 关于SpringMVC中的转发与重定向的说明
  4. 【HDU】6242-Geometry Problem
  5. http无状态和鉴权解决四种方案
  6. Redis 常用命令整理
  7. LC 94. Binary Tree Inorder Traversal
  8. MySQL 聚合函数与count()函数
  9. 怎么处理sqlserver2017部署在winowsDocker上时区无法修改成功的方式,并且可以多创建新的容器调用简单的方式直接使用!
  10. 网易云音乐ncm加密格式批量转换为flac,mp3