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;
    }
    
  • 相关阅读:
    December 23rd 2016 Week 52nd Friday
    December 22nd 2016 Week 52nd Thursday
    December 21st 2016 Week 52nd Wednesday
    December 20th 2016 Week 52nd Tuesday
    December 19th 2016 Week 52nd Sunday
    December 18th 2016 Week 52nd Sunday
    uva294(唯一分解定理)
    uva11624Fire!(bfs)
    fzu2150Fire Game(双起点bfs)
    poj3276Face The Right Way
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12019522.html
Copyright © 2011-2022 走看看