LightOJ - 1326 - Race(DP)

链接:

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\n", ans);
    }

    return 0;
}
posted @ 2019-12-10 22:06  YDDDD  阅读(157)  评论(0编辑  收藏  举报