zoukankan      html  css  js  c++  java
  • Race UVA

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, Munsiji came into their life. Munsiji took them to derby (horse racing). Munsiji enjoyed the race, but as usual Disky and Sooma did their as usual task instead of passing some romantic moments. They were thinking- in how many ways a race can finish! Who knows, maybe this is their romance! In a race there are n horses. You have to output the number of ways the race can finish. Note that, more than one horse may get the same position. For example, 2 horses can finish in 3 ways.
    1. Both first
    2. horse1 first and horse2 second
    3. horse2 first and horse1 second
    Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case starts with a line containing an integer n (1 ≤ n ≤ 1000).
    Output
    For each case, print the case number and the number of ways the race can finish. The result can be very large, print the result modulo 10056.
    Sample Input
    3 1 2 3
    Sample Output
    Case 1: 1 Case 2: 3 Case 3: 13

    分析:

    题目大意:
    n个人比赛,排名可以并列,问有多少种情况

    分析
    假设n-1个人,排出了m个名次;新来1人,与前面某名次并列,有f(n-1,m)*m种结果
    假设n-1个人,排出了m-1个名次;新来1人,与前面名次都不并列,有f(n-1,m-1)*m种结果
    f(n,m)= f(n-1,m)*m + f(n-1,m-1)*m

    code:

    #include<stdio.h>
    #include<algorithm>
    #include<memory.h>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    #define INF 0x3f3f3f3f
    #define max_v 1005
    #define mod 10056
    int f[max_v];
    int dp[max_v][max_v];//dp[i][j]:i个人比赛 j种排名 的情况数目
    int main()
    {
    
        dp[0][0]=1;
        int sum;
        for(int i=1;i<max_v;i++)
        {
            sum=0;
           for(int j=1;j<=i;j++)
           {
                dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod*j%mod;
                sum=(sum+dp[i][j])%mod;//i个人比赛 总情况数
           }
           f[i]=sum;
        }
        int t,c=1;
        scanf("%d",&t);
        int n;
        while(t--)
        {
            scanf("%d",&n);
            printf("Case %d: %d
    ",c++,f[n]);
        }
        return 0;
    }
  • 相关阅读:
    JSP详细解析
    JSP详细解析
    JAVA设计模式之单例模式
    JAVA设计模式之单例模式
    SQLite – GLOB子句
    HEXO进阶打赏
    python常用模块
    猫头鹰的深夜翻译:核心JAVA并发一
    标准规范
    题解 P1951 【收费站_NOI导刊2009提高(2)】
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9371217.html
Copyright © 2011-2022 走看看