Problem 2594 --Counting Permutations

2594: Counting Permutations

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
When Tonyfang was studying monotonous queues, he came across the following problem:
For a permutation of length n a1,a2...an, define li as maximum x satisfying x<i and ax>ai, or 0 if such x not exists, ri as minimum x satisfying x>i and ax>ai, or n+1 if not exists. Output ∑ni=1min(i−li,ri−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 ∑ni=1min(i−li,ri−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≤n≤200,1≤x≤109. P is a prime and 108≤P≤109, 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

推荐代码 查看2594 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战 淡意的温柔 606332 2020-07-09 15:35:07

赛题来源/所属竞赛 HDU N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛