编程介的小学生 2019-05-10 15:49 采纳率: 20.5%
浏览 239

数学级数问题在算法理论上的运用,怎么采用C程序的代码的编写的方式去有效实现这个算法?

Problem Description
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 xai, 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!

Input
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.

Output
For every test case, output the number of valid permutations modulo P.

Sample Input
998244353
3 4
3 233

Sample Output
2
0

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题