QOJ.ac

QOJ

Límite de tiempo: 5 s Límite de memoria: 1024 MB Puntuación total: 100

#3005. 单调性

Estadísticas

给定一个 $r \times c$ 的网格。网格中的每个单元格都填有一个 $1$ 到 $r \times c$ 之间的整数,且每个单元格的数字各不相同。

如果一个数字网格的每一行和每一列都是单调递增或单调递减的(每一行或每一列的单调性可以不同),则称该网格为单调的。

网格的子网格定义如下:首先选择行和列的非空子集,然后取这些选定行和列的交集处的元素,并保持其相对顺序。

给定网格共有 $(2^r-1)(2^c-1)$ 个非空子网格。请计算其中有多少个是单调的。

考虑以下网格:

$$ \begin{matrix} 1 & 2 & 5\\ 7 & 6 & 4\\ 9 & 8 & 3 \end{matrix} $$

共有 $9$ 个 $1 \times 1$ 的子网格,$9$ 个 $1 \times 2$ 的子网格,$3$ 个 $1 \times 3$ 的子网格,$9$ 个 $2 \times 1$ 的子网格,$9$ 个 $2 \times 2$ 的子网格,$3$ 个 $2 \times 3$ 的子网格,$3$ 个 $3 \times 1$ 的子网格,$3$ 个 $3 \times 2$ 的子网格以及 $1$ 个 $3 \times 3$ 的子网格。它们都是单调的,因此共有 $9+9+3+9+9+3+3+3+1 = 49$ 个单调子网格。

输入格式

每个测试用例的第一行包含两个空格分隔的整数 $r$ 和 $c$ ($1 \leq r, c \leq 20$),表示网格的维度。

接下来的 $r$ 行,每行包含 $c$ 个空格分隔的整数 $x$ ($1 \leq x \leq r \times c$,所有 $x$ 均唯一),表示网格内容。

输出格式

输出一个整数,表示给定网格中单调子网格的数量。

样例

样例输入 1

3 3
1 2 5
7 6 4
9 8 3

样例输出 1

49

样例输入 2

4 3
8 2 5
12 9 6
3 1 10
11 7 4

样例输出 2

64

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.