시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 8 | 3 | 3 | 50.000% |
Given $n$ and $k$, calculate the expected number of vertices in the suffix automaton of a random string of length $n$ over alphabet of size $k$. If $r$ is the answer, output $r\cdot k^n$ modulo $10^9 + 7$.
The first line contains the number of tests $T$. Each of the next $T$ lines contains integers $n$ and $k$ ($1 \le k \le n \le 40$). All tests in the input are different.
Output $T$ lines with answers for tests.
3 2 2 4 3 10 2
12 447 14972
Let $S(s)$ be the set of all substrings of $s$. Suffix automaton of a string $s$ is the smallest directed acyclic graph with a specified vertex $v_0$ and an assignment $l(e)$ of characters to all edges of $G$ that satisfies the following property: $S(s) = \{l(e_1)\ldots l(e_k) \mid (e_1, \ldots, e_k)\text{ --- a path starting at }v_0\}$.