zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1326

    题意:

    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
      

    思路:

    Dp[i][j] 表示一共i匹马,分成j批冲线。
    Dp[i][j] = Dp[i-1][j]j+Dp[i-1][j-1]j

    代码:

    // #include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int MOD = 10056;
    const int MAXN = 1e6+10;
    
    int Dp[1010][1010];
    int n;
    
    void Init()
    {
        Dp[0][0] = 1;
        for (int i = 1;i <= 1000;i++)
        {
            for (int j = 1;j <= i;j++)
                Dp[i][j] = (Dp[i-1][j-1]*j%MOD + Dp[i-1][j]*j%MOD)%MOD;
        }
    }
    
    int main()
    {
        // freopen("test.in", "r", stdin);
        Init();
        int t, cas = 0;
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d", &n);
            printf("Case %d:", ++cas);
            int ans = 0;
            for (int i = 1;i <= n;i++)
                ans = (ans+Dp[n][i])%MOD;
            printf(" %d
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    除adsense外适合英文站的国外广告联盟(4/12/2011更新)
    盛大云和阿里云之云主机初体验
    【行文格式】
    在线PDF阅读&编辑网站一览
    做销售不得不看的20部电影
    VS中的Code Snippet来提高开发效率
    10个免费的javascript富文本编辑器(jQuery and nonjQuery)
    【操作命令】
    SQLServer常见查询问题
    代码検索
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12019522.html
Copyright © 2011-2022 走看看