No.616 Strange Sort
Problem Statement
Ebi-chan is studying sorting. One day, she found a strange sort called "tsutaj sort". Apparently, it is used to quickly obtain a sequence that is roughly in ascending order.
When a sequence $a$ is tsutaj-sorted, it always returns a sequence $a'$ whose inversion number is at most $K$. Here, the inversion number is the number of pairs $(i, j)$ such that $i < j$ and $a_i' > a_j'$.
Ebi-chan is curious how many possible sequences there are after tsutaj sort. Find the total number of rearrangements of the given sequence whose inversion number is at most $K$, modulo $1,000,000,007$.
Input
$N$ $K$ $a_1$ $a_2$ $\dots$ $a_N$
The input is given in $2$ lines.
The $1$st line contains the length $N$ of the sequence and the upper bound $K$ on the inversion number of the sorted sequence.
The $2$nd line contains the sequence $a$. The $i$-th element is $a_i$.
Constraints
- $1 \leq N \leq 300$
- $0 \leq K \leq \frac{N(N-1)}{2}$
- $1 \leq a_i \leq 10^9$
- All $a_i$ are distinct. That is, if $i \neq j$ then $a_i \neq a_j$.
Output
Output in $1$ line the total number of rearrangements of the given sequence whose inversion number is at most $K$, modulo $1,000,000,007$.
Sample
Sample 1
Input
3 1 1 2 3
Output
3
There are $3$ sequences satisfying the condition.
-
1 2 3(inversion number $0$) -
1 3 2(inversion number $1$) -
2 1 3(inversion number $1$)
Sample 2
Input
5 7 1 4 5 8 2
Output
106
Sample 3
Input
13 78 3 1 4 15 9 2 6 5 35 89 7 93 23
Output
227020758
Note that you should output the remainder modulo $1,000,000,007$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tsutaj
はむこ