当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7133:Subpermutation

题目描述
A permutation of $n$ is a sequence of length $n$ in which each number from $1$ to $n$ appears exactly once. A $\textit{full-permutation}$ of $n$ is a sequence that connects all permutations of $n$ into one sequence in lexicographical order. Sequence $p_1, p_2, \dots, p_n$ is lexicographically smaller than $q_1, q_2, \dots, q_n$ if $p_i \lt q_i$ where $i$ is the minimum index satisfying $p_i \neq q_i$.

Here are some symbols used in this problem:

- $p_n$: the full-permutation of $n$. For example, $p_3 = \{1,2,3,1,3,2,2,1,3,2,3,1,3,1,2,3,2,1\}$ .
- $S_n$: the set of all permutations of $n$. For example, $S_3=\{\{1,2,3\},\{1,3,2\},\{2,1,3\},\{2,3,1\},\{3,1,2\},\{3,2,1\}\}$.
- $f(s,t)$: the number of contiguous subsequences in $s$ that are equal to $t$. For example, $f(\{1,2,12,1,2\},\{1,2\})=2$.

Now given $n$ and $m$, please calculate $\sum_{t\in{S_m}}f(p_n,t)$ modulo $10^9+7$.
输入解释
The first line contains one integer $T\ (1\le T\le 10^5)$, indicating the number of test cases.

The only line for each case contains two integers $n\ (1\le n\le 10^6)$ and $m\ (1\le m\le n)$, as described in the description.
输出解释
For each test case, output a single integer $\sum_{t\in{S_m}}f(p_n,t)$ modulo $10^9+7$.
输入样例
4
2 1
2 2
3 2
4 3
输出样例
2
2
4
15
来自杭电HDUOJ的附加信息
Hint For the third case in the sample, $p_3 = \{1,2,3,1,3,2,2,1,3,2,3,1,3,1,2,3,2,1\}$, $S_2=\{\{1,2\},\{2,1\}\}$. There are $4$ contiguous subsequences in $p_3$ that are equal to $\{1,2\}$ or $\{2,1\}$: $\{\underline{1,2},3,1,3,2,\underline{2,1},3,2,3,1,3,\underline{1,2},3,\underline{2,1}\}$.

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7133

最后修改于 2021-10-23T19:11:39+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)