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

建议使用的浏览器:

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

6310:Counting Permutations

题目描述
When Tonyfang was studying monotonous queues, he came across the following problem:
For a permutation of length n $a_1,a_2...a_n$, define $l_i$ as maximum x satisfying $x<i$ and $a_x>a_i$, or 0 if such x not exists, $r_i$ as minimum x satisfying $x>i$ and $a_x > a_i$, or n+1 if not exists. Output $\sum_{i=1}^n \min(i-l_i,r_i-i)$.
Obviously, this problem is too easy for Tonyfang. So he thought about a harder version:
Given two integers n and x, counting the number of permutations of 1 to n which $\sum_{i=1}^n \min(i-l_i,r_i-i)=x$ where l and r are defined as above, output the number mod P.
Tonyfang solved it quickly, now comes your turn!
输入解释
In the first line, before every test case, an integer P.
There are multiple test cases, please read till the end of input file.
For every test case, a line contain three integers n and x, separated with space.
$1 \leq n \leq 200, 1 \leq x \leq 10^9$. P is a prime and $10^8 \leq P \leq 10^9$, No more than 10 test cases.
输出解释
For every test case, output the number of valid permutations modulo P.
输入样例
998244353
3 4
3 233
输出样例
2
0
来自杭电HDUOJ的附加信息
Recommend chendu

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

源链接: HDU-6310

最后修改于 2020-10-25T23:30:11+00:00 由爬虫自动更新

共提交 0

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