HDU 5894 hannnnah_j’s Biological Test ——(组合数)
思路来自于:http://blog.csdn.net/lzedo/article/details/52585170。
不过并不需要卢卡斯定理,直接组合数就可以了。
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + ;
const int N = + ; int m,n,k;
int fac[N];
int qpow(int a,int b)
{
int ans = ;
while(b)
{
if(b&) ans = 1LL* ans * a % mod;
b >>= ;
a = 1LL* a * a % mod;
}
return ans;
} int C(int n,int m)
{
if(n<m) return ;
return 1LL* fac[n] * qpow(1LL*fac[m]*fac[n-m]%mod,mod-) % mod;
} void init()
{
fac[] = ;
for(int i=;i<N;i++)
{
fac[i] = 1LL* fac[i-] * i % mod;
}
} int main()
{
init();
int T;scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
if(m==) printf("%d\n",n);
else
{
printf("%d\n",(int)(1LL*C(n-m*k-,m-)*n%mod*qpow(m,mod-)%mod));
}
}
}
HDU 5894 hannnnah_j’s Biological Test ——(组合数)的更多相关文章
- hdu 5894 hannnnah_j’s Biological Test 组合数学
传送门:hdu 5894 hannnnah_j’s Biological Test 题目大意:n个座位,m个学生,使每个学生的间隔至少为k个座位 组合中的插空法 思路:每个学生先去掉k个空位间隔,剩下 ...
- HDU 5894 hannnnah_j’s Biological Test【组合数学】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5894 题意: 一个圆桌上有$n$个不同的位置,$m$个相同的人安排到这$n$个位置上,要求两人相邻的 ...
- HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛
题目链接 #include <map> #include <queue> #include <math.h> #include <stdio.h> #i ...
- HDU 5894 hannnnah_j’s Biological Test
题目链接:传送门 题目大意:有n张板凳围成一圈,有m个人,要让m个人都坐到凳子上且任意两人之间相隔>=k 个凳子,问有多少种方法%(1e9+7) 题目思路:组合数学 我们这样考虑,既然每个人相距 ...
- hdu 5894(组合数取模)
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- 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 ...
- 排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- HDU 5059 Harry And Biological Teacher
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5069 题意:给出n个串,m个询问,每个询问(u,v),求u的一个最长后缀是v的前缀. 思路:离线.将关于u ...
随机推荐
- 【原创】大数据基础之Logstash(6)mongo input
logstash input插件之mongodb是第三方的,配置如下: input { mongodb { uri => 'mongodb://mongo_server:27017/db' pl ...
- 【原创】大数据基础之ETL vs ELT or DataWarehouse vs DataLake
ETL ETL is an abbreviation of Extract, Transform and Load. In this process, an ETL tool extracts the ...
- MVC4学习要点记三
一.数据迁移用来解决code first情况下当增加.删除.改变实体类,或改变DbContext类后,相应地更新数据库结构而不会对现有数据产生影响. 1.启用迁移指令:enable-migration ...
- redis的keys常用操作及redis的特性
redis的keys常用操作 1.获得所有的keys: keys * 2.可以模糊查询 keys:keys my* 3.删除keys:del mymkey1 mykey2 4.是否存在keys:ex ...
- 原生html、js手写 radio与checkbox 美化
原生html.js手写 radio与checkbox 美化 html <!DOCTYPE html> <html> <head> <meta charse ...
- golang编写二叉树
最近开始找golang 开发工程师职位,针对算法相关二叉树相关常用面试题搞一遍: package tree import ( "math" "fmt&qu ...
- mybatis-03
mybatis-03 1.mybatis的别名[两种]在MyBatis中可以为变量类型定义别名.简化映射文件的定义,在核心配置文件中定义的别名.别名应用:MyBatis框架先将resultType定义 ...
- mybatis框架中 动态代理的问题
在配置文件时候 id唯一性 所以不允许重载 <select id=" querydemo" resultType="pojo"> sql 语句 ...
- python常用模块:模块练习
今日作业: 1.简述 什么是模块 模块就将一些函数功能封装在一个文件内,以‘文件名.py’命名,以“import 文件名”方式调用 模块有哪些来源 自定义.内置.DLL编译器.包模块的格式要求有哪些 ...
- VSCode远程连接Docker
一.Docker开启远程访问 [root@local host ~]# vi /lib/systemd/system/docker.service #修改ExecStart这行 ExecStart=/ ...