CF1536E.Omkar and Forest

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Omkar's most recent follower, Ajit, has entered the Holy Forest. Ajit realizes that Omkar's forest is an nn by mm grid (1≤n,m≤20001 \leq n, m \leq 2000) of some non-negative integers. Since the forest is blessed by Omkar, it satisfies some special conditions:

  1. For any two adjacent (sharing a side) cells, the absolute value of the difference of numbers in them is at most 11.
  2. If the number in some cell is strictly larger than 00, it should be strictly greater than the number in at least one of the cells adjacent to it.

Unfortunately, Ajit is not fully worthy of Omkar's powers yet. He sees each cell as a "0" or a "#". If a cell is labeled as "0", then the number in it must equal 00. Otherwise, the number in it can be any nonnegative integer.

Determine how many different assignments of elements exist such that these special conditions are satisfied. Two assignments are considered different if there exists at least one cell such that the numbers written in it in these assignments are different. Since the answer may be enormous, find the answer modulo 109+710^9+7.

奥姆卡尔最近的追随者阿吉特进入了圣林。阿吉特意识到,奥姆卡尔的森林是一个 n×mn \times m 的网格(1≤n,m≤20001 \leq n, m \leq 2000),其中每个格子填有一个非负整数。由于该森林受奥姆卡尔祝福,它满足如下特殊条件:

  1. 对任意两个相邻(共享一条边)的格子,其中数字之差的绝对值至多为 11;
  2. 若某个格子中的数字严格大于 00,则它必须严格大于其至少一个相邻格子中的数字。

不幸的是,阿吉特尚未完全配得上奥姆卡尔的力量。他只能将每个格子识别为 "0" 或 "#":若某格被标记为 "0",则其中的数字必须等于 00;否则,其中的数字可以是任意非负整数。

请确定满足上述特殊条件的数字赋值方案总数。若存在至少一个格子,在两种赋值方案中填入的数字不同,则认为这两种方案不同。由于答案可能极大,请输出答案对 109+710^9+7 取模的结果。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \leq t \leq 100). Description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤2000,nm≥21 \leq n, m \leq 2000, nm \geq 2) – the dimensions of the forest.

nn lines follow, each consisting of one string of mm characters. Each of these characters is either a "0" or a "#".

It is guaranteed that the sum of nn over all test cases does not exceed 20002000 and the sum of mm over all test cases does not exceed 20002000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \leq t \leq 100)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤20001 \leq n, m \leq 2000,且 nm≥2nm \geq 2)——表示森林的尺寸。

接下来是 nn 行,每行由一个长度为 mm 的字符串组成。这些字符串中的每个字符均为 "0" 或 "#"。

保证所有测试用例中 nn 的总和不超过 20002000,且所有测试用例中 mm 的总和不超过 20002000。

输出格式

For each test case, print one integer: the number of valid configurations modulo 109+710^9+7.

对于每个测试用例,输出一个整数:有效配置的数量对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    4
    3 4
    0000
    00#0
    0000
    2 1
    #
    #
    1 2
    ##
    6 29
    #############################
    #000##0###0##0#0####0####000#
    #0#0##00#00##00####0#0###0#0#
    #0#0##0#0#0##00###00000##00##
    #000##0###0##0#0##0###0##0#0#
    #############################

    输出#1

    2
    3
    3
    319908071

说明/提示

For the first test case, the two valid assignments are

0000000000000000\\ 0000\\ 0000

and

0000001000000000\\ 0010\\ 0000

对于第一个测试用例,两个有效的赋值为

0000000000000000\\ 0000\\ 0000

和

0000001000000000\\ 0010\\ 0000

输入解题思路,AI测评打分。不知道怎么写?

首页