hannnnah_j’s Biological Test

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 681    Accepted Submission(s): 235

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.

 
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
2
4 2 6
5 2 1
 
Sample Output
0
5
 
Source
 
题意:n个位子,m个人,每两个人之间至少隔k个位置,问排的方式?
题解:设第一个人和第二个人之间的距离为 a1,第二个和第三个之间距离为 a2 ... 第 n个人和第1 个人之间距离为 an;
a1+...+an = n-m....1
ai>=k                ....2
解方程 1,2得解为 C(n-m*k-1,m-1)
第一个人有n种放法,所以答案要乘n,m个人没有区别,答案要除 m.
这场比赛真心不爽,1010坑了3个小时,然后这个题目最后把组合数写出来了,刚好59分快5点了,然后没交上去....交上去...事后在hdu AC....又是2个题..
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const long long p = 1e9+;
typedef long long LL;
LL pow_mod(LL a,LL n)
{
LL ans=;
while(n)
{
if(n&) ans=ans*a%p;
a=a*a%p;
n>>=;
}
return ans;
}
LL cm(LL n,LL m,LL mod)
{
if(m>n) return ;
LL i,ans=,a,b;
for(i=; i<m; i++)
{
a=(n-i)%mod;
b=(m-i)%mod;
ans=ans*( a*pow_mod(b,mod-)%mod )%mod;
}
return ans;
}
LL lucas(LL n,LL m,LL p)
{
if(m==) return ;
return ( cm(n%p,m%p,p)*lucas(n/p,m/p,p) )%p;
} int main()
{
int T;
long long n,m,k;
scanf("%d",&T);
while(T--)
{
scanf("%lld %lld %lld",&n,&m,&k);
LL a = lucas(n-m*k-,m-,p);
LL c = pow_mod(m,p-)%p;
printf("%lld\n",((a*n)%p*c)%p); }
return ;
}

hdu 5894(组合数取模)的更多相关文章

  1. 排列组合+组合数取模 HDU 5894

    // 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...

  2. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  3. 组合数取模Lucas定理及快速幂取模

    组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1)  , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...

  4. [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】

    题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...

  5. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...

  6. 2015 ICL, Finals, Div. 1 Ceizenpok’s formula(组合数取模,扩展lucas定理)

    J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. BZOJ_2142_礼物_扩展lucas+组合数取模+CRT

    BZOJ_2142_礼物_扩展lucas+组合数取模 Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同 ...

  8. 组合数取模&&Lucas定理题集

    题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020  输出组合数C(n, m) mod p (1 ...

  9. 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数

    typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...

随机推荐

  1. 洛谷 P3723 [AH2017/HNOI2017]礼物 解题报告

    P3723 [AH2017/HNOI2017]礼物 题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手环,一个留给自己,一个送给她.每个手环上各有 \(n\) 个 ...

  2. 【翻译】InterlockedIncrement内部是如何实现的?

        Interlocked系列函数可以对内存进行原子操作,它是如何实现的?     它的实现依赖于底层的CPU架构.对于某些CPU来说,这很简单,例如x86可以通过LOCK前缀直接支持Interl ...

  3. [linux]codeblocks开发mysql配置

    1.在安装好mysql后,可以应该安装必要的库文件 $sudo apt-get install libmysqlclient-dev 2.将codeblocks与mysql的库文件连接起来 在code ...

  4. zabbix 监控服务器的TCP状态

    本文介绍如何监控TCP的11种状态: 1.命令选择: ss or netstat netstat 在 Centos7上已经不再支持,ss 打印基于socket的统计信息,实际运行下来,ss的速度比ne ...

  5. 解决ajax chrome禁止本地浏览时加载本地其他文件的方法

    在chrome快捷键右键--属性 “ --allow-file-access-from-files ”,前面用空格隔开.然后应用--确定.

  6. Discrete Logging(POJ2417 + BSGS)

    题目链接:http://poj.org/problem?id=2417 题目: 题意: 求一个最小的x满足a^x==b(mod p),p为质数. 思路: BSGS板子题,推荐一篇好的BSGS和扩展BS ...

  7. 20、什么样的项目适合Web自动化测试

    1.什么是Web自动化测试?概念:让程序代替人为自动验证Web项目功能的过程 2.什么Web项目适合做自动化测试 1.需求变动不频繁 2.项目周期长 3.项目需要回归测试 3.如阿进行Web自动化测试 ...

  8. JS中短路运算符&&和||

    在JS函数中我们经常会使用到短路运算符,主要是逻辑与(&&) 和 逻辑或(||) 1.逻辑与 && 的运算方式 var a = 5 && 6; cons ...

  9. 去除IE10+上文本框巨丑无比的删除图标以及显示密码图标

    去除IE10+上文本框巨丑无比的删除图标以及显示密码图标 IE浏览器总是让人喜欢让人厌,在最新的IE浏览器(IE10+)上使用表单时,文本框内后面会出现很巨丑无比的“删除图标”以及“显示密码图标”,如 ...

  10. ecshop代码修改后提交,无法立即生效

    今天帮一朋友部署一网站.成品的ecshop模版站.在搭建好xammp集成环境,导入数据库,修改配置文件后,报了一大堆错. 其中第一个是关于废弃preg_replace中/e这种用法的,因为存在漏洞,一 ...