E - Decreasing Subsequence Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 10001000

問題文

整数 N,KN,K が与えられます. 以下の条件をすべて満たす整数列 A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N) を,よい数列と呼ぶことにします.

  • 0Aii0 \leq A_i \leq i (1iN1 \leq i \leq N)
  • 各整数 v=1,2,,Nv=1,2,\cdots,N について,Ai=vA_i=v となる ii は高々 11 つ.

すべてのよい数列 AA について以下の問題の答えを足し合わせた値を 109+710^9+7 で割った余りを求めてください.

  • AA の長さ KK の(連続するとは限らない)部分列であって,正整数のみからなり,かつ単調減少であるようなものは何通りあるか求めよ. 別の言い方をすれば,添字の列 1i1<i2<<iKN1 \leq i_1 < i_2 < \cdots < i_K \leq N であって, Ai1>Ai2>>AiK1A_{i_1}>A_{i_2}>\cdots>A_{i_K} \geq 1 を満たすものの個数を求めよ.

制約

  • 3N50003 \leq N \leq 5000
  • 2K2 \leq K
  • 2K1N2K-1 \leq N
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる.

NN KK

出力

答えを出力せよ.


入力例 1Copy

Copy
3 2

出力例 1Copy

Copy
1

例えば A=(0,2,1)A=(0,2,1) はよい数列であり,条件を満たす部分列の個数は 11 です. それ以外のよい数列の例としては A=(0,1,0),(1,2,3),(0,0,0)A=(0,1,0),(1,2,3),(0,0,0) などが考えられますが,どれも条件を満たす部分列が存在しません. 結局,A=(0,2,1)A=(0,2,1) 以外のよい数列は条件を満たす部分列を持たず,よって答えは 11 になります.


入力例 2Copy

Copy
6 2

出力例 2Copy

Copy
660

入力例 3Copy

Copy
10 3

出力例 3Copy

Copy
242595

入力例 4Copy

Copy
100 10

出力例 4Copy

Copy
495811864

Score : 10001000 points

Problem Statement

You are given integers NN and KK. Let us call an integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N) good when it satisfies all of the conditions below.

  • 0Aii0 \leq A_i \leq i (1iN1 \leq i \leq N)
  • For every integer v=1,2,,Nv=1,2,\cdots,N, there is at most one index ii such that Ai=vA_i=v.

Find the sum, modulo (109+7)(10^9+7), of the answers to the following problem for all good sequences AA.

  • Find the number of length-KK (not necessarily contiguous) subsequences of AA consisting of positive integers that are decreasing. In other words, find the number of sequences of indices 1i1<i2<<iKN1 \leq i_1 < i_2 < \cdots < i_K \leq N such that Ai1>Ai2>>AiK1A_{i_1}>A_{i_2}>\cdots>A_{i_K} \geq 1.

Constraints

  • 3N50003 \leq N \leq 5000
  • 2K2 \leq K
  • 2K1N2K-1 \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print the answer.


Sample Input 1Copy

Copy
3 2

Sample Output 1Copy

Copy
1

For example, A=(0,2,1)A=(0,2,1) is a good sequence, with one subsequence satisfying the condition. There are other good sequences such as A=(0,1,0),(1,2,3),(0,0,0)A=(0,1,0),(1,2,3),(0,0,0), but none of them has subsequences satisfying the condition. In the end, no good sequence other than A=(0,2,1)A=(0,2,1) has subsequences satisfying the condition, so the answer is 11.


Sample Input 2Copy

Copy
6 2

Sample Output 2Copy

Copy
660

Sample Input 3Copy

Copy
10 3

Sample Output 3Copy

Copy
242595

Sample Input 4Copy

Copy
100 10

Sample Output 4Copy

Copy
495811864


2025-04-08 (Tue)
05:39:37 +00:00