Rank
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 604 Accepted Submission(s): 307
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
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.
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
Author
teddy
Source
Recommend
teddy
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=110;
const int mod=20090126;
LL dp[maxn][maxn],f[maxn];
void Init(int n){
dp[0][0]=1;f[0]=1;
for(int i=1;i<=n;i++){
f[i]=i*f[i-1]%mod;
for(int j=1;j<=i;j++)
dp[i][j]=((j%mod*dp[i-1][j]%mod)%mod+dp[i-1][j-1]%mod)%mod;
}
}
int main()
{
int t,n;
Init(100);
scanf("%d",&t);
while(t--){
LL ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
ans=(ans+dp[n][i]*f[i])%mod;
printf("%I64d\n",ans);
}
return 0;
}