2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元
hannnnah_j’s Biological Test
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 802 Accepted Submission(s): 269
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.
The next T lines were given n, m, k, respectively.
0 < m < n < 1e6, 0 < k < 1000
5
nn 的环,选 mm 个位置涂黑,要求相邻两个黑点之间至少间隔 kk 个白点,问方案数。ans = n * C(n - m*k -1,m - 1)/m;
乘n相当于第一个人有n种选择,而学生在这里都是一样的,所以要是重复计算了m次,最后除以m。
逆元 费马小处理
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
#define N 1000000000
using namespace std;
ll quickmod(ll a,ll b)
{
ll sum=;
while(b)
{
if(b&)
sum=(sum*a)%mod;
b>>=;
a=(a*a)%mod;
}
return sum;
}
ll combine1(ll n,ll m) //计算组合数C(n,m)
{
if(n<||m<)
return ;
ll sum=; //线性计算
for(ll i=,j=n;i<=m;i++,j--)
sum=(((sum*j)%mod)*quickmod(i,mod-))%mod;
return sum;
}
int t;
ll nn,mm,kk;
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=;i<=t;i++)
{
scanf("%I64d %I64d %I64d",&nn,&mm,&kk);
if(mm==)
printf("%I64d\n",nn);
else
printf("%I64d\n",(((combine1(nn-mm*kk-,mm-)%mod)*quickmod(mm,mod-))%mod*nn)%mod);
}
}
return ;
}
2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元的更多相关文章
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2016 ACM/ICPC Asia Regional Shenyang Online
I:QSC and Master 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5900 题意: 给出n对数keyi,vali表示当前这对数的键值和权值 ...
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
Friends and Enemies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
随机推荐
- nginx日志切割
脚本完成后将其存入 Nginx 安装目录的 sbin 中,取名为 cut-log.sh,之后使用 crontab -e 新增一个定时任务,在其中增加执行这个脚本: #!/bin/bash ## 零点执 ...
- zabbix3.0部署(LAMP)
0.1 初始化 #!/bin/sh yum clean all systemctl stop firewalld.service systemctl disable firewalld.service ...
- 利用smarty call函数实现无限极分类
定义一个function {function name=menu level=0} <ul class="level{$level}"> {foreach $data ...
- Linux - gcc和g++的区别
一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...
- 关于Xcode调试的帖子,感觉不错,转来看看
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 http://www.raywenderlich.com/10505 ...
- SharePoint 2016 的新特性概览(二)(What's New for IT Professionals in SharePoint Server 2016)
博客地址:http://blog.csdn.net/FoxDave SharePoint 2016 的新特性 三. 监测和数据(Insights and Data) 实时数据监测,包括对使用情况.存储 ...
- ios 检测应用程序升级问题
app 上其实已经有自动检测我们版本的功能. 其实我也觉得对于一个程序员来说检测功能让,系统来维护更合适和合理.开发者只要告诉苹果即可. 然而今天老大非要实现自己版本更新的问题,因此也查找了相关的资 ...
- 关于process
http://docs.oracle.com/javase/1.5.0/docs/api/ The ProcessBuilder.start() and Runtime.exec methods cr ...
- poj1160 dp
//Accepted 564 KB 63 ms //和hdu1227一样 //dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]) //初始化条件,dp[0][ ...
- 利用pl/sql developer进行远程连接oracle server出现的问题及解决办法
由于本人刚刚给自己的笔记本做了系统,由原来的32位系统编程现在的64位系统,所以,很多软件由于兼容性,不得不重新安装...当我安完了pl/sql developer工具后,就满心欢喜的去连接远程ora ...