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关闭屏幕时不锁屏实现
    android Seekbar 拖动按钮显示不全问题
    webview在compileSdkVersion 大于等于23 android6.0以上系统执行js代码异常,但是在compileSdkVersion小于23 android6.0以下系统却执行正常问题
    Seekbar扩大点击区域
    android .9背景图作为TextView背景时文字无法居中问题
    android 使用系统级别权限
    自定义ViewPager,避免左右滑动时与水平滑动控件冲突
    ListVIew中包含水平滑动控件,左右滑动时容易触发上下滑动
    Android输入法挤乱布局问题
    android WebView缩放时卡顿问题
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5885717.html
Copyright © 2011-2022 走看看