JZOJ 5235. 【NOIP2017模拟8.7A组】好的排列
来源:互联网 发布:淘宝选款技巧 编辑:程序博客网 时间:2024/06/07 00:33
5235. 【NOIP2017模拟8.7A组】好的排列
(File IO): input:permutation.in output:permutation.out
Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits
Description
对于一个1->n的排列 ,定义A中的一个位置i是好的,当且仅当Ai-1>Ai 或者Ai+1>Ai。对于一个排列A,假如有不少于k个位置是好的,那么称A是一个好的排列。
现在有q个询问,每个询问给定n,k,问有多少排列是好的。答案对10^9+7取模。
Input
输入文件名为permutation.in。
首先输入q。
接下来输入q个询问n,k 。
Output
输出文件名为permutation.out。
输出q行,每行一个整数代表答案。
Sample Input
8
4 3
6 4
10 7
20 14
50 40
100 72
1000 900
3000 2000
Sample Output
8
448
1433856
868137807
908422882
609421284
150877522
216180189
Data Constraint
对于20%的数据,n<=10,q=1
对于40%的数据,n<=20,q=1
对于60%的数据,n<=100
对于100%的数据,n,k<=3000,q<=10000
题解
dp题
题目中 好处 定义是 当且仅当
这个不好处理
我们可以转化成 坏处 为 当且仅当
用
如果第
如果第
答案就是
代码
#include<cstdio>#include<algorithm>#define mo 1000000007#define Q 10010#define N 3010long n[Q],m[Q];long long f[N][N];int main(){ long tot,i,j,ans,maxn=0,maxm=0; freopen("permutation.in","r",stdin); freopen("permutation.out","w",stdout); scanf("%ld",&tot); for(i=1;i<=tot;i++){ scanf("%ld%ld",&n[i],&m[i]); maxn=std::max(maxn,n[i]); maxm=std::max(maxm,m[i]); } f[1][0]=1; for(i=2;i<=maxn;i++) for(j=1;j<i;j++){ f[i][j]=(f[i-1][j-1]*(i-j)*2%mo+f[i-1][j]*(i-(i-1-j)*2)%mo)%mo; } for(i=1;i<=tot;i++){ ans=0; for(j=n[i];j>=m[i];j--) ans=(ans+f[n[i]][j])%mo; printf("%ld\n",ans); } return 0;}
- JZOJ 5235. 【NOIP2017模拟8.7A组】好的排列
- JZOJ5235. 【NOIP2017模拟8.7A组】好的排列
- JZOJ 5234. 【NOIP2017模拟8.7A组】外星人的路径
- JZOJ 100045. 【NOIP2017提高A组模拟7.13】好数
- JZOJ 5236. 【NOIP2017模拟8.7A组】利普希茨
- JZOJ 5236. 【NOIP2017模拟8.7A组】利普希茨
- 【JZOJ 5429】【NOIP2017提高A组集训10.27】排列
- JZOJ 5230. 【NOIP2017模拟A组模拟8.5】队伍统计
- JZOJ 5230. 【NOIP2017模拟A组模拟8.5】队伍统计
- JZOJ 5453. 【NOIP2017提高A组冲刺11.5】好路线
- JZOJ 5462. 【NOIP2017提高A组冲刺11.8】好文章
- 【JZOJ 4931】【NOIP2017提高组模拟12.24】A
- 【JZOJ 4931】【NOIP2017提高组模拟12.24】A
- JZOJ 5195. 【NOIP2017提高组模拟7.3】A
- JZOJ 100026. 【NOIP2017提高A组模拟7.7】图
- JZOJ 100030. 【NOIP2017提高A组模拟7.8】为了爱情
- jzoj. 100031. 【NOIP2017提高A组模拟7.9】外星密码
- JZOJ 100035【NOIP2017提高A组模拟7.10】区间
- 6.Circular Sequence
- [Noip2011]计算系数
- Android Messenger实现IPC通信
- 8.7 WJ的逃离escape 2537
- 【linux shell】 find 常用选项
- JZOJ 5235. 【NOIP2017模拟8.7A组】好的排列
- spring资源访问
- HTML CSS:Getting Serious with HTML
- 303. Range Sum Query
- 安装NVIDIA显卡驱动+CUDA+CUDNN+NVCAFFE的问题总结
- bzoj 2829 计算几何
- 8.7 约数个数shlqsh 2535
- 堆排序
- vs2015编译mysql-connector-cpp-1.1.9