HDU 5894 组合数学
来源:互联网 发布:淘宝卖品牌要授权吗 编辑:程序博客网 时间:2024/05/29 18:44
hannnnah_j’s Biological Test
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 235 Accepted Submission(s): 66
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个不同的座位,现在让m个同学坐下,两个同学之间的座位间必须有k个空位, 问有多少种坐法,答案mod1e9+7.
题解:
首先构造出m个人,两个人旁边有k-1个座位,那问题就变成了m个正数的和是n-k*m
考虑n-k*m划分为m个正数
t | t | t | t | t | t | t | t | t | t | t | t
由于是正数,所以每个数都必须大于0,那么挡板就不能放在两边
这时候选法就是c(n-k*m-1,m-1)
n个不同的座位环形,所以起点有n种可能,ans再乘n
有m个同学,以每个人为起点算了1次,相当于多算到m次,ans除以m
ps:先判掉m=1,再判掉n<m*m+k这两种情况
然后除法用逆元
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;const ll mod=1e9+7;ll mo[1000005];ll quickmod(ll a,ll k,ll m){ll ans=1;a%=m;while(k){if(k&1){ans=ans*a%m;}a=a*a%m;k>>=1;}return ans;}void init(){mo[1]=1;mo[0]=1;for(ll i=2;i<=1000000;i++){mo[i]=i*mo[i-1]%mod;}}ll quickpow(ll a,ll b,ll k){ll ans=0;a%=k;while(b){if(b&1){ans=(ans+a)%k;}a=(a<<1)%k;b>>=1;}return ans;}int main(){ll t;init();scanf("%lld",&t);while(t--){ll n,m,k;scanf("%lld%lld%lld",&n,&m,&k);if(m==1){printf("%lld\n",n);continue;}if(n<m+m*k){printf("0\n");continue;}ll ans=mo[n-k*m-1]*n%mod;ll t=quickmod(((mo[m-1]*mo[n-k*m-1-m+1]%mod)*m%mod+mod)%mod,mod-2,mod);ans=((ans*t%mod)+mod)%mod;cout<<ans<<endl;}return 0;}
0 0
- HDU 5894 组合数学
- hdu 4373 组合数学
- hdu 3944 组合数学
- hdu 4045 组合数学
- HDU -1261 组合数学。
- HDU Candy(数学 组合)
- HDU 1027 组合数学
- hdu 1220组合数学
- HDU 5651 组合数学
- HDU 5698 组合数学
- hdu 4602 组合数学
- HDU-3037 (组合数学)
- HDU 3944 组合数学+数论
- hdu 1249 三角形 组合数学
- HDU 4909 String(组合数学)
- hdu 1220 Cube (组合数学)
- HDU 5159 Card (组合数学)
- HDU 4390 组合数学&数论
- ThreadLocal实现线程范围的共享变量
- spring security 返回具体登陆错误信息
- View的滑动
- 计网--OSI七层与TCP/IP五层网络架构详解
- chapter 8:Graphical Models(图模型)
- HDU 5894 组合数学
- python安装及环境配置
- 加载cell的xib的两种方式
- 利用缓存机制来实现对页面的优化
- JAVA EE-SESSION&COOKIE
- HDU 5895 Mathematician QSC(欧拉定理推广)
- AS汇编器源码剖析-第5章-用eclipse编译调试AS
- 【Thinking in Java】初始化与清理(一)
- 【Think in Java】学习笔记_Class对象