hannnnah_j’s Biological Test HDU
来源:互联网 发布:淘宝小二介入买家输 编辑:程序博客网 时间:2024/06/08 14:08
hannnnah_j is a teacher in WL High school who teaches biology.One day, she wants to test m students, thus she arranges n different seats around a round table.In order to prevent cheating, she thinks that there should be at least k empty seats between every two students.hannnnah_j is poor at math, and she wants to know the sum of the solutions.So she turns to you for help.Can you help her? The answer maybe large, and you need to mod 1e9+7.
Input
First line is an integer T(T≤1000).
The next T lines were given n, m, k, respectively.
0 < m < n < 1e6, 0 < k < 1000
Output
For each test case the output is only one integer number ans in a line.
Sample Input
24 2 65 2 1
Sample Output
05
这题是一个组合数学的题,因为每个椅子是不一样的,所以其实看成链状的而不是环,我们假定链的第一个位置已经坐了人,并且顺带带走了k*m个点,而且我们把1+k个点浓缩成一个点,那么m-1个这样的点来放剩下的n-1-k*m个格子即可,然后我们可以截成n种不同的链所以要乘n,但是有因为是循环放置的,而且每个人是相同的所以通构的会有m种,因为是旋转的,所以要除m。
m等于1的时候要特判
#include<iostream>#include<cstdio>#include<cstring>#define mod 1000000007#define N 1000005using namespace std;long long fac[N];long long inv[N];long long P(long long a,long long b){ long long ans=1; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans;}long long get(int n,int m){ return (fac[n]*inv[m]%mod)*inv[n-m]%mod;}void init(){ fac[0]=1; inv[0]=1; for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod; inv[N-1]=P(fac[N-1],mod-2); for(int i=N-2;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;}int main(){ init(); int n,m,k; int t; //cout<<get(10,5)<<endl; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); if(m==1) printf("%d\n",n); else if(n<(k+1)*m) printf("0\n"); else { long long ans=get(n-1-k*m,m-1); ans=ans*n%mod; ans=ans*P(m,mod-2)%mod; printf("%lld\n",ans); } } return 0;}
阅读全文
0 0
- hannnnah_j’s Biological Test HDU
- hannnnah_j’s Biological Test HDU
- hannnnah_j’s Biological Test HDU
- hdu 5894 hannnnah_j’s Biological Test 排列组合
- hdu 5894 hannnnah_j’s Biological Test
- hannnnah_j’s Biological Test
- hdu5894 hannnnah_j’s Biological Test
- 沈阳网赛1003 HDU 5894 hannnnah_j’s Biological Test
- HDU 5894 hannnnah_j’s Biological Test (组合数学)
- HDU 5894 hannnnah_j’s Biological Test(组合数学)
- HDU 5894 hannnnah_j’s Biological Test 组合数取模
- HDU-5894-hannnnah_j’s Biological Test(组合数取模)
- Hdu-5894 hannnnah_j’s Biological Test(组合数学)
- HDU5894-hannnnah_j’s Biological Test【组合数学】
- hdu5894 hannnnah_j’s Biological Test(数学)
- hannnnah_j’s Biological Test (lucas定理 )
- 2016 ACM/ICPC Reginal Shengyang hdu 5894 hannnnah_j’s Biological Test (数学推导 Lucas)
- 2016 ACM/ICPC Asia Regional Shenyang Online HDU 5894 hannnnah_j’s Biological Test
- Java核心技术点之集合框架
- 不可变类
- List中的泛型
- 洛谷 P2290 [HNOI2004]树的计数(bzoj[1211])
- ubuntu libnice编译测试
- hannnnah_j’s Biological Test HDU
- Codeforces 190E Counter Attack【思维+Bfs】好题!
- CentOS7使用firewalld打开关闭防火墙与端口
- 将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5
- angularJS 路由不能正常工作 URL中出现#!
- 归并排序
- 心情随笔
- 正则表达式小结
- java中的线程、进程、锁