ICPC-第三场网络赛-3-hannnnah_j’s Biological Test(组合数应用)
来源:互联网 发布:xmanager连接linux图形 编辑:程序博客网 时间:2024/04/28 12:02
hannnnah_j’s Biological Test
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 180 Accepted Submission(s): 49
Problem Description
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.
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
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
题目大意:老师为防止学生作弊,因此让n个学生坐在一张大圆桌考试,这个圆桌有n个座位,总共有m个学生
,但是规定任意两个学生之间必须各k个座位,问你有多少种坐法(ps:学生之间看做相同,但是座位不同)。
题解:组合数公式的拓展(详见代码)
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<limits.h>#include<algorithm>#include<queue>#include<stack>#include<vector>#include<math.h>#include<map>using namespace std;#define maxn 1000001#define Mod 1000000007long long n,m,k,a[maxn],b[maxn];long long zuhe(long long x,long long y){return a[x]*b[x-y]%Mod*b[y]%Mod;}long long Pow(long long x,long long y){long long ans=1;while(y){if(y&1) ans=ans*x%Mod;x=x*x%Mod;y/=2;}return ans;}int main(){int T,i,j;scanf("%d",&T);a[0]=b[0]=1;for(i=1;i<maxn;i++){ a[i]=a[i-1]*i%Mod; b[i]=Pow(a[i],Mod-2)%Mod; } while(T--) { scanf("%lld%lld%lld",&n,&m,&k); long long ans; if(m==1) ans=n; else if(m*(k+1)>n)ans=0; else { ans=zuhe(n-m*k,m)%Mod; ans=(ans+zuhe(n-m*k-1,m-1)*k)%Mod; } printf("%lld\n",ans); }}
0 0
- ICPC-第三场网络赛-3-hannnnah_j’s Biological Test(组合数应用)
- hdu5894 hannnnah_j’s Biological Test(2016 acm/icpc 沈阳网络赛,组合数学)
- HDU 5894-hannnnah_j’s Biological Test(大组合数模板Lucas)
- hdu-5894-hannnnah_j’s Biological Test(Lucas定理+乘法逆+组合数)
- HDU5894-hannnnah_j’s Biological Test(组合数学+Lucas定理)
- HDU 5894 hannnnah_j’s Biological Test (组合数学)
- hdu5894 hannnnah_j’s Biological Test(组合数学)
- HDU-5894-hannnnah_j’s Biological Test(组合数取模)
- HDU5894-hannnnah_j’s Biological Test【组合数学】
- hannnnah_j’s Biological Test
- 2016 ACM/ICPC Asia Regional Shenyang Online hannnnah_j’s Biological Test【组合数学】
- hdu5894 hannnnah_j’s Biological Test(数学)
- 2016ACM-ICPC沈阳网络预选赛1003 hannnnah_j's Biological Test
- 2016ACM-ICPC沈阳网络预选赛1003 hannnnah_j's Biological Test
- 【HDU5894 2016 ACM ICPC Asia Regional Shenyang Online C】【组合数 隔板法】hannnnah_j’s Biological Test n个不同座位成
- 2016 ACM/ICPC Reginal Shengyang hdu 5894 hannnnah_j’s Biological Test (数学推导 Lucas)
- HDU 5894 hannnnah_j’s Biological Test(组合数学)
- HDU 5894 hannnnah_j’s Biological Test 组合数取模
- 源代码到可执行代码的过程以及Makefile的编写
- HDU 5900 QSC and Master(区间DP)
- 传统jdbc的缺点
- css基础知识(一)
- JAVA基础--类加载&对象创建过程
- ICPC-第三场网络赛-3-hannnnah_j’s Biological Test(组合数应用)
- 如何用十条命令在一分钟内检查Linux服务器性能
- Redis应用——使用Redis存储Session
- HDU 5505 GT and numbers【思维+GCD】
- Java 版本的单项链表插入
- 41. First Missing Positive
- VC++获取本机所有IP和掩码信息
- 第三周项目4-顺序表应用(1)
- 【Derivation】随机过程及应用(三) - 高斯分布/正态分布的期望和方差