zoukankan      html  css  js  c++  java
  • hdu-5894 hannnnah_j’s Biological Test(组合数学)

    题目链接:

    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('
    ');
    }
      
    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);continue;}
            if(n<m*(k+1))printf("0
    ");
            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
    ",ans);
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    Android应用开发提高系列(1)——《Practical Java 中文版》读书笔记(上)
    Android开发指南(35) —— Toast Notifications
    Android开发指南(37) —— Data Backup
    Android开发指南(36) —— Search
    [转]闲话操作系统1
    [从架构到设计]第二回:对象的旅行对象和人,两个世界,一样情怀
    [Thinking]从赢在中国,思考博客园的商业化
    [你必须知道的.NET]目录导航
    070809
    [CLR团队公告]CLR基础研究团队纲领
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5885717.html
Copyright © 2011-2022 走看看