Light OJ 1095 Arrange the Numbers(计数)
来源:互联网 发布:java模拟器安卓4.4.2版 编辑:程序博客网 时间:2024/05/05 04:38
Consider this sequence {1, 2, 3 ... N}, as an initial sequence of first N natural numbers. You can rearrange this sequence in many ways. There will be a total of N! arrangements. You have to calculate the number of arrangement of first N natural numbers, where in first M positions; exactly K numbers are in their initial position.
For Example, N = 5, M = 3, K = 2
You should count this arrangement {1, 4, 3, 2, 5}, here in first 3 positions 1 is in 1st position and 3 in 3rd position. So exactly 2 of its first 3 are in there initial position.
But you should not count {1, 2, 3, 4, 5}.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case contains three integers N (1 ≤ N ≤ 1000), M (M ≤ N), K (0 < K ≤ M).
Output
For each case, print the case number and the total number of possible arrangements modulo 1000000007.
Sample Input
Output for Sample Input
2
5 3 2
10 6 3
Case 1: 12
Case 2: 64320
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int mod=1000000007;LL dp[1010],C[1010][1010];void init(){ C[1][1]=C[1][0]=C[0][0]=1; for(int i=2;i<=1000;i++) { C[i][i]=C[i][0]=1; for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } dp[1]=0;dp[2]=1;dp[0]=1; for(int i=3;i<=1000;i++) dp[i]=1LL*(i-1)*(dp[i-1]+dp[i-2])%mod;}LL Cal(int n,int m,int k){ int x=n-m; int y=m-k; LL ans=0; for(int i=0;i<=x;i++) ans=(ans+C[x][i]*dp[y+i]%mod)%mod; return ans*C[m][k]%mod;}int main(){ init(); int t,cas=1; int n,m,k; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); printf("Case %d: %lld\n",cas++,Cal(n,m,k)); } return 0;}
- Light OJ 1095 Arrange the Numbers(计数)
- Light oj 1095 - Arrange the Numbers(错排)
- Light OJ 1095 Arrange the Numbers (容斥)
- uva 11481 - Arrange the Numbers(计数问题)
- LightOJ-1095 Arrange the Numbers
- Light OJ 1382 The Queue(组合计数)
- lightoj 1095 - Arrange the Numbers (错排数)
- lightoj 1095 - Arrange the Numbers 组合数学
- uva11481 Arrange the Numbers(错位排列)
- uva 11481 Arrange the Numbers
- UVa:11481 Arrange the Numbers
- UVA - 11481 Arrange the Numbers
- LightOJ 1095 Arrange the Numbers (容斥原理)
- UVA 11481 - Arrange the Numbers(组合数学)
- UVA 11481 Arrange the Numbers (容斥)
- lightoj1095 Arrange the Numbers 组合数学
- Light oj 1060 - nth Permutation(dfs 计数)
- Light oj 1105 - Fi Binary Number(计数)
- SQL子查询and左右连接
- uva 11426 - GCD - Extreme (II) 欧拉函数
- 第4周项目1-单链表的建立(补充项)
- 原码, 反码, 补码 详解
- 2015年开学典礼∣校长陈十一:选择,从Innovation Capital出发
- Light OJ 1095 Arrange the Numbers(计数)
- Objective-c Method Swizzling的详细使用方法
- Unity3D中鼠标旋转物体
- 定时器的使用
- Qt数据库之添加MySQL驱动插件
- Python应用(一) 识别网站验证码以及识别算法
- 1165 火烧赤壁 vijosoj (数组模拟)
- thinkphp——制作一个输出调试函数,随时调试
- 高通|AR扫描图片播放视频