Rank HDU - 2643(第二类Stirling数)

Problem Description
Recently in Teddy’s hometown there is a competition named “Cow Year Blow Cow”.N competitors had took part in this competition.The competition was so intense that the rank was changing and changing.
Now the question is:
How many different ways that n competitors can rank in a competition, allowing for the possibility of ties.
as the answer will be very large,you can just output the answer MOD 20090126.
Here are the ways when N = 2:
P1 < P2
P2 < P1
P1 = P2

Input
The first line will contain a T,then T cases followed.
each case only contain one integer N (N <= 100),indicating the number of people.

Output
One integer pey line represent the answer MOD 20090126.

Sample Input
2
2
3

Sample Output
3
13

大致题意:n位选手参加比赛,每个选手有一个排名,有可能有并列,那么排名情况有多少种可能?

思路:假设不同排名的数量为i,那么就是把n个选手分到i个集合中,即求第二类Stirling数
结果为:
这里写图片描述

代码如下

#include <cstdio>  
#include <cstring>  
#include <algorithm> 
#include <iostream> 
using namespace std;  
#define ll long long   
const int mod=20090126;
using namespace std;
ll stir[150][150];
ll f[150];
void init(){
        f[1]=1;
    for(int i=2;i<=100;i++)  
        f[i]=i*f[i-1]%mod;  

    memset(stir,0,sizeof(stir));  
    stir[0][0]=0;  
    stir[1][1]=1;  
    for(int i=2;i<=100;i++)  
       for(int j=1;j<=i;j++)  
         stir[i][j]=(stir[i-1][j-1]+j*stir[i-1][j]%mod)%mod;  
}
int main ()  
{    
    init();

    int T;
    scanf("%d",&T); 
    while(T--)
    {
        int n;
        scanf("%d",&n);
        ll sum=0;
        for(int i=1;i<=n;i++)
        sum=(sum+stir[n][i]*f[i]%mod)%mod;

        printf("%lld\n",sum);
    }
    return 0;  
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值