首页 > 代码库 > uva 12034 Race

uva 12034 Race

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int M=10056;
const int N=1024;
int c[N][N];

int main()
{
    int f[N],cas,t,i,j,n;

    for(i=0;i<N;i++)
    {
        c[i][0]=c[i][i]=1;
        for(j=1;j<i;j++)
        {
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%M;
        }
    }
    f[0]=1;
    for(i=1;i<N;i++)
    {
        f[i]=0;
        for(j=1;j<=i;j++)
        {
            f[i]=(f[i]+c[i][j]*f[i-j])%M;
        }
    }

    scanf("%d",&t);
    for(cas=1;cas<=t;cas++)
    {
        scanf("%d",&n);
        printf("Case %d: %d\n",cas,f[n]);
    }
    return 0;
}
<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

uva 12034 Race