hdu-5894 hannnnah_j’s Biological Test(组合数学)

解决一个生物老师安排学生在圆桌周围就座的问题,确保每两个学生间至少隔开k个座位,通过组合数学的方法计算可能的排列总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:

hannnnah_j’s Biological Test

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


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
 
题意:
 
给出n个不同的围成一圈的座位,现在有m个人,要求每两个人之间要空至少k个座位,问有多少种方案;
 
思路:
 
m个人要坐m个座位,还要至少空m*k个座位,剩下的就是n-m*(k+1)个座位了,放在m个间隔中,就是相同的球放在不同的盒子那个模型了;
C(n-m*k-1,m-1),然后n个不同的座位那么就可以有n种不同的开始方式,然后这其中的每一种方式都被算了m次;
所以C(n-m*k-1,m-1)*n/m就是答案了;
 
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>
  
using namespace std;
  
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
  
typedef  long long LL;
  
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}
  
const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=(1<<20)+10;
const int maxn=1e6+10;
const double eps=1e-12;
 
int n,m,k;
LL p[maxn];
inline void Init()
{
    p[0]=1;
    p[1]=1;
    for(int i=2;i<maxn;i++)p[i]=p[i-1]*(LL)i%mod;
}
LL pow_mod(LL x,LL y)
{
    LL s=1,base=x;
    while(y)
    {
        if(y&1)s=s*base%mod;
        base=base*base%mod;
        y>>=1;
    }
    return s;
}
int main()
{
    //freopen("int.txt","r",stdin);
    Init();
    int t;
    read(t);
    while(t--)
    {
        read(n);read(m);read(k);
        if(m==1){printf("%d\n",n);continue;}
        if(n<m*(k+1))printf("0\n");
        else 
        {
            int fn=n-k*m-1,fm=m-1;
            LL ans=p[fn]*pow_mod(p[fm]*p[fn-fm]%mod,mod-2)%mod;
            ans=ans*n%mod*pow_mod((LL)m,mod-2)%mod;
            printf("%lld\n",ans);
        }
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5885717.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值