#P1044. [NOIP 2003 普及组] 栈

    ID: 44 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>动态规划,dp数学递推2003NOIp 普及组卡特兰,Catalan

[NOIP 2003 普及组] 栈

Description

Ningning considers the following problem: given an operand sequence 1,2,,n1, 2, \ldots, n (the figure illustrates the case for 11 to 33), stack A has depth greater than nn.

Two operations are allowed:

  1. Move a number from the head of the operand sequence to the top of the stack (corresponding to the stack push operation).
  2. Move a number from the top of the stack to the end of the output sequence (corresponding to the stack pop operation).

Using these two operations, one operand sequence can produce a set of output sequences. The following figure shows the process of generating the sequence 2 3 1 from 1 2 3.

(The initial state is as shown above.)

For a given nn, your program should compute and output the total number of output sequences that can be obtained from the operand sequence 1,2,,n1, 2, \ldots, n through these operations.

Input Format

The input contains a single integer nn (1n181 \leq n \leq 18).

Output Format

Output a single line containing the total number of possible output sequences.

3

5

Hint

Source: NOIP 2003 Junior, Problem 3.

Translated by ChatGPT 5