102932: [Atcoder]ABC293 C - Make Takahashi Happy

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:6 Solved:0

Description

Score : $300$ points

Problem Statement

There is a grid with $H$ horizontal rows and $W$ vertical columns. For two integers $i$ and $j$ such that $1 \leq i \leq H$ and $1 \leq j \leq W$, the square at the $i$-th row from the top and $j$-th column from the left (which we denote by $(i, j)$) has an integer $A_{i, j}$ written on it.

Takahashi is currently at $(1,1)$. From now on, he repeats moving to an adjacent square to the right of or below his current square until he reaches $(H, W)$. When he makes a move, he is not allowed to go outside the grid.

Takahashi will be happy if the integers written on the squares he visits (including initial $(1, 1)$ and final $(H, W)$) are distinct. Find the number of his possible paths that make him happy.

Constraints

  • $2 \leq H, W \leq 10$
  • $1 \leq A_{i, j} \leq 10^9$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$H$ $W$
$A_{1, 1}$ $A_{1, 2}$ $\ldots$ $A_{1, W}$
$A_{2, 1}$ $A_{2, 2}$ $\ldots$ $A_{2, W}$
$\vdots$
$A_{H, 1}$ $A_{H, 2}$ $\ldots$ $A_{H, W}$

Output

Print the answer.


Sample Input 1

3 3
3 2 2
2 1 3
1 5 4

Sample Output 1

3

There are six possible paths:

  • $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 2, 3, 4$, so he will not be happy.
  • $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 1, 3, 4$, so he will not be happy.
  • $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 1, 5, 4$, so he will be happy.
  • $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 1, 3, 4$, so he will not be happy.
  • $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 1, 5, 4$, so he will be happy.
  • $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$: the integers written on the squares he visits are $3, 2, 1, 5, 4$, so he will be happy.

Thus, the third, fifth, and sixth paths described above make him happy.


Sample Input 2

10 10
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100

Sample Output 2

48620

In this example, every possible path makes him happy.

Input

题意翻译

给定一个 $n\times m$ 的方格,每一个格子上都有一个数字 $A_{i,j}$。 一条从 $(1,1)$ 到 $(n,m)$ 的路径能让 Takahashi 开心当且仅当这条路径上没有重复的数且没有往上或往左移动。 求有几条路径能让 Takahashi 开心。 $n,m\le10$。

Output

分数:300分

问题描述

有一个有$H$行和$W$列的网格。对于两个整数$i$和$j$,使得$1 \leq i \leq H$和$1 \leq j \leq W$,在离顶部第$i$行、离左侧第$j$列的方格(我们表示为$(i, j)$)上写着一个整数$A_{i, j}$。

现在,Takahashi在$(1,1)$。从现在开始,他重复向右或向下移动到他当前方格的相邻方格,直到他到达$(H, W)$。当他移动时,他不允许离开网格。

如果Takahashi访问的方格(包括起始的$(1, 1)$和最终的$(H, W)$)上的整数是唯一的,他将会感到高兴。找出使他高兴的可能路径的数量。

限制条件

  • $2 \leq H, W \leq 10$
  • $1 \leq A_{i, j} \leq 10^9$
  • 输入中的所有值都是整数。

输入

输入通过标准输入以以下格式给出:

$H$ $W$
$A_{1, 1}$ $A_{1, 2}$ $\ldots$ $A_{1, W}$
$A_{2, 1}$ $A_{2, 2}$ $\ldots$ $A_{2, W}$
$\vdots$
$A_{H, 1}$ $A_{H, 2}$ $\ldots$ $A_{H, W}$

输出

打印答案。


样例输入1

3 3
3 2 2
2 1 3
1 5 4

样例输出1

3

有六种可能的路径:

  • $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 2, 3, 4$,所以他< strong >不会< /strong >感到高兴。
  • $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 1, 3, 4$,所以他< strong >不会< /strong >感到高兴。
  • $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 1, 5, 4$,所以他< strong >会< /strong >感到高兴。
  • $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 1, 3, 4$,所以他< strong >不会< /strong >感到高兴。
  • $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 1, 5, 4$,所以他< strong >会< /strong >感到高兴。
  • $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$:他访问的方格上的整数是$3, 2, 1, 5, 4$,所以他< strong >会< /strong >感到高兴。

因此,上述的第三、第五和第六条路径使他感到高兴。


样例输入2

10 10
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100

样例输出2

48620

在这个例子中,每一条可能的路径都会使他感到高兴。

HINT

n*m的棋盘,从左上角走到右下角,每次只能往下或者往右走到相邻格子,有多少条路径上的数字是各不相同的?

加入题单

算法标签: