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;
}