QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#8353. T1

Statistics

小 T 有一个 $n\times m$ 的矩阵 $A$,$A$ 中的元素互不相同,可以构成一个 $1\sim nm$ 的排列。

如果一个序列是升序或者降序的,则称这个序列是好的。如果一个矩阵的每一行是好的,每一列也是好的,则称这个矩阵是好的。

求有多少个 $A$ 的非空子矩阵是好的。

一个矩阵的非空子矩阵是指,选出行的一个非空子集与列的一个非空子集,既在这些行又在这些列的元素排成的新矩阵。可以发现,一个 $n\times m$ 的矩阵的非空子矩阵数为 $(2^n-1)(2^m-1)$。

输入格式

第一行两个整数 $n,m$,表示矩阵大小。

接下来 $n$ 行,每行 $m$ 个整数 $A_{i,j}$,表示矩阵 $A$ 的元素。

输出格式

一行一个整数表示答案。

样例输入 1

2 2
1 3
2 4

样例输出 1

9

样例输入 2

2 3
2 3 1
4 5 6

样例输出 2

19

样例输入 3

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

样例输出 3

79

样例解释

样例 $1$ 中所有子矩阵均满足要求。

样例 $2$ 中只有子矩阵为整个矩阵,或第一行的所有数时不满足要求。

数据范围

对于所有数据,$1\leq n,m\leq 20$,$1\leq A_{i,j}\leq nm$,保证 $A_{i,j}$ 互不相同。

子任务 $1$($20$ 分):$n,m\leq 10$。

子任务 $2$($25$ 分):$n,m\leq 15$。

子任务 $3$($25$ 分):$n,m\leq 18$。

子任务 $4$($30$ 分):无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.