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. 洛谷 P1514 引水入城 解题报告

    P1514 引水入城 题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 NN 行 \times M×M 列的矩形,如上图所示,其中每个格 ...

  2. CF 566A Matching Names

    CF 566A Matching Names 题目描述 给出n个名字和n个昵称,求一个名字和昵称的劈配方案,使得被劈配的名字和昵称的最长公共前缀长度的和最大. 1<=n<=100000 字 ...

  3. windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹

    windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹 译:by  backlion 0x00前言 当微软发布MS17-010漏洞的补丁时,该漏洞影响的范围是从Win ...

  4. [pool www] user has not been defined

    [02-Dec-2014 00:28:58] ALERT: [pool www] user has not been defined [02-Dec-2014 00:28:58] ERROR: fai ...

  5. 51nod求助

    求助dalao们,51nod1170实在是不会了,有没有大佬讲一下,有兴趣的可以告诉我,我提供AC代码. using System; using System.Collections.Generic; ...

  6. Python之旅:数字、字符串

    一 数字 整型与浮点型 #整型int 作用:年纪,等级,身份证号,qq号等整型数字相关 定义: age=10 #本质age=int(10) #浮点型float 作用:薪资,身高,体重,体质参数等浮点数 ...

  7. struts2 - View页面中获取Action的成员变量

    struts2 - View页面中获取Action的成员变量 2016年03月02日 11:04:44 IT男青年 阅读数:1074   View页面中获取Action的成员变量 按照Struts的设 ...

  8. STL源码分析-bitset

    http://note.youdao.com/noteshare?id=0ea12c1fffd3866c6eddb8dc208c109d

  9. bzoj 1879 状压dp

    879: [Sdoi2009]Bill的挑战 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 852  Solved: 435[Submit][Status ...

  10. css等比例分割父级容器(完美三等分)

    html部分代码: 方法一: 浮动布局+百分比 (将子元素依次左浮动,根据子元素的个数,设定每个子元素的宽度百分比) 方法二:行内元素(inline-block)+百分比 方法三: 父元素  disp ...