hdu5894hannnnah_j’s Biological Test+组合数学+Lucas

来源:互联网 发布:生日快乐网页源码 编辑:程序博客网 时间:2024/05/12 08:02

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
2016 ACM/ICPC Asia Regional Shenyang Online
n个位子,m个人,每两个人之间至少隔k个位置,问排的方式。。
原题一道,没什么好写的了。。。
最后n/m那里先乘n再乘逆元炸了。先取个膜。wa两发!弱!
这里写图片描述

#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#define LL long longusing namespace std;LL n,m,p,k;LL quick_mod(LL a, LL b){    LL ans = 1;    a %= p;    while(b)    {        if(b & 1)        {            ans = ans * a % p;            b--;        }        b >>= 1;        a = a * a % p;    }    return ans;}LL C(LL n, LL m){    if(m > n) return 0;    LL ans = 1;    for(int i=1; i<=m; i++)    {        LL a = (n + i - m) % p;        LL b = i % p;        ans = ans * (a * quick_mod(b, p-2) % p) % p;    }    return ans;}LL Lucas(LL n, LL m){    if(m == 0) return 1;    return C(n % p, m % p) * Lucas(n / p, m / p) % p;}int main(){    int t;    p=1000000007;    scanf("%d",&t);    while(t--){        scanf("%I64d %I64d %I64d",&n,&m,&k);        long long int A=n-m*k-1;        long long int B=m-1;        long long out;        out=Lucas(A,B)*n%p;        out=out*quick_mod(m,p-2)%p;        printf("%I64d\n",out);    }    return 0;}
0 0
原创粉丝点击