cf1228B B. Filling the Grid

2024-04-16 02:38
文章标签 grid filling cf1228b

本文主要是介绍cf1228B B. Filling the Grid,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Suppose there is a ℎ×? grid consisting of empty or full cells. Let’s make some definitions:

?? is the number of consecutive full cells connected to the left side in the ?-th row (1≤?≤ℎ). In particular, ??=0 if the leftmost cell of the ?-th row is empty.
?? is the number of consecutive full cells connected to the top end in the ?-th column (1≤?≤?). In particular, ??=0 if the topmost cell of the ?-th column is empty.
In other words, the ?-th row starts exactly with ?? full cells. Similarly, the ?-th column starts exactly with ?? full cells.

These are the ? and ? values of some 3×4 grid. Black cells are full and white cells are empty.
You have values of ? and ?. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of ? and ?. 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).

Input
The first line contains two integers ℎ and ? (1≤ℎ,?≤103) — the height and width of the grid.

The second line contains ℎ integers ?1,?2,…,?ℎ (0≤??≤?) — the values of ?.

The third line contains ? integers ?1,?2,…,?? (0≤??≤ℎ) — the values of ?.

Output
Print the answer modulo 1000000007(109+7).

Examples
inputCopy
3 4
0 3 1
0 2 3 0
outputCopy
2
inputCopy
1 1
0
1
outputCopy
0
inputCopy
19 16
16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12
6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4
outputCopy
797922655
Note
In the first example, this is the other possible case.

In the second example, it’s impossible to make a grid to satisfy such ?, ? values.

In the third example, make sure to print answer modulo (109+7).
被Hack了,一场掉灰。。。
记得考虑不成立的情况

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>using namespace std;typedef long long ll;
const ll maxn = 1e3 + 7;
const ll mod = 1e9 + 7;
ll r[maxn],c[maxn];
ll maze[maxn][maxn];ll p[1000007];void init()
{p[0] = 1;for(ll i = 1;i <= 1000000;i++){p[i] = p[i - 1] * 2 % mod;}
}int main()
{ll h,w;scanf("%lld%lld",&h,&w);for(ll i = 1;i <= h;i++){scanf("%lld",&r[i]);}for(ll i = 1;i <= w;i++){scanf("%lld",&c[i]);}memset(maze,-1,sizeof(maze));for(ll i = 1;i <= h;i++){if(r[i] == 0){maze[i][1] = 0;}else{for(ll j = 1;j <= r[i];j++){maze[i][j] = 1;}}}for(ll i = 1;i <= w;i++){if(c[i] == 0){maze[1][i] = 0;}else{for(ll j = 1;j <= c[i];j++){maze[j][i] = 1;}}}for(int i = 1;i <= h;i++){if(r[i] == 0){if(maze[i][1] != 0){printf("0\n");return 0;}}else{int tmp = 0;for(int j = 1;j <= w;j++){if(maze[i][j] != 1)break;tmp++;if(tmp > r[i]){printf("0\n");return 0;}}if(tmp < r[i]){printf("0\n");return 0;}}}for(int i = 1;i <= w;i++){if(c[i] == 0){if(maze[1][i] != 0){printf("0\n");return 0;}}else{int tmp = 0;for(int j = 1;j <= h;j++){if(maze[j][i] != 1)break;tmp++;if(tmp > c[i]){printf("0\n");return 0;}}if(tmp < c[i]){printf("0\n");return 0;}}}ll cnt = 0;for(ll i = 1;i <= h;i++){for(ll j = 1;j <= w;j++){if(maze[i][j] == -1){ll flag1 = 0,flag2 = 0;for(ll ci = i - 1;ci >= 1;ci--){if(maze[ci][j] == -1 || maze[ci][j] == 0){flag1 = 1;break;}}for(ll cj = j - 1;cj >= 1;cj--){if(maze[i][cj] == -1 || maze[i][cj] == 0){flag2 = 1;break;}}if(flag1 && flag2)cnt++;}}}init();printf("%lld\n",p[cnt]);return 0;
}

这篇关于cf1228B B. Filling the Grid的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907599

相关文章

LibSVM学习(六)——easy.py和grid.py的使用

我们在“LibSVM学习(一)”中,讲到libSVM有一个tools文件夹,里面包含有四个python文件,是用来对参数优选的。其中,常用到的是easy.py和grid.py两个文件。其实,网上也有相应的说明,但很不系统,下面结合本人的经验,对使用方法做个说明。        这两个文件都要用python(可以在http://www.python.org上下载到,需要安装)和绘图工具gnup

nyoj 695 Judging Filling Problems

一道强大的模拟题。。。 只要学会<string>类的运用即可。。。 注意: 1、细节的处理。 2、问题的分情况讨论。。 附上代码: 有好对缀余的地方,希望大神前来更新。 #include<stdio.h>#include<string.h>#include<string>#include<iostream>using namespace std;int num[1000

extjs 获取grid的选中行的某列的值

我的情景是这样的:一个grid(就叫gridA吧),最后一列的每行都是超链接,点击超链接时会弹出一个窗体,这个窗体也需要一个grid(gridB)展示,并且呢,gridB所需的数据需要gridA里的某列的值(把这个列叫做Param)作为参数。于是就产生了点击gridA的某行的超链接,获取该行的Param列的值这样的需求。 不知道为什么,我用var param=this.grid..getSe

Extjs Grid 根据列的值(0或者1)显示“是或否”

grid中:{header:'是否解析',dataIndex:'isExplain',align:'center',sortable: true,renderer:isResend}, 写一个函数: function isResend(data, metadata, record){ var resend; if(record.data.isExplain==0){resend="否";

extjs中grid,设置CheckboxSelectionModel的默认值

Grid(命名为BasicGrid)中定义了:this.sm = new Ext.grid.CheckboxSelectionModel();。表示一列checkBox。 情景:上面Grid所在的窗口弹出之后,选择一项(我这里是只选一项)点击确定之后关闭该窗口。当需要再次弹出该窗口时,把刚刚已经选择的那一项打上勾。下面是方法:我是写在弹出该窗口的方法中的。

AngularJS的ui-grid的列表数据实现换行

在公共css中添加如下: .ui-grid-cell-contents-break { padding: 5px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; overflow: hidden; height: 100%; word-break: break

【ag-grid】列宽设置不生效探索

发现使用sizeColumnsToFit()会覆盖默认设置的宽度 解决方案1 给某一列的列定义设置为suppressSizeToFit设置为:true 核心代码: gridColumns: (ColDef | ColGroupDef)[] = [{checkboxSelection: true,headerCheckboxSelection: true,suppressSizeToFit:

vue3 vxe-grid 当前高亮行的背景颜色+字体颜色,要求随着主题的颜色的改变而改变。

1、先上个图: 2、点击的行的颜色与字体的颜色,并没有随时主题的颜色而改变: const gridOptions = reactive<BasicTableProps>({id: 'userTable',showHeaderOverflow: false,showOverflow: true,keepSource: true,columns: userColumns,pagerConfig

F - Rook on Grid 矩阵 侧面视角 树状数组

两种走法 先下再右 吃到的就是L[i]-1个 先右再下 就吃剩的哈哈 每个L[i]挡住的阴影部分 才是有效的吃到部分 关于阴影 🔥可以想象从矩阵右侧有光线照进来。然后被障碍物挡住的那些空格。 处理方式可以按照列扫过去。一边用树状数组维护那些有阴影的行 实现的主要部分就是怎么去维护那些阴影。 小tip:>=r[i]都当做第一列开始就有阴影 题目 #include <bits/stdc++.h>

C# wpf Grid中实现控件拖动调整大小

WPF拖动改变大小系列 第一节 Grid内控件拖动调整大小(本章) 第二节 Canvas内控件拖动调整大小 第三节 窗口拖动调整大小 第四节 附加属性实现拖动调整大小 第五章 拓展更多调整大小功能 文章目录 WPF拖动改变大小系列前言一、功能说明二、如何实现?1.继承Adorner2.使用Thumb3.实现拖动逻辑 三、完整代码四、使用示例总结 前言 在《C# wpf