Ranking Problem

Ranking Problem

Time Limit:1000MS  Memory Limit:65536K
Total Submit:80 Accepted:14

Description

If you are a LOLer, then you must be very familiar with LPL league. In the spring of 2016 LPL league game to take the points system, if a team won in BO3, then increase 1 point, failure does not buckle points, followed by each team based on the standings, the higher the ranking the higher the points, the same points if the same rank.Then only if there are n teams participating, the total number of cases the ranking in the game? 
For example, 2 teams ranking has 3 ways. 
1. Both first 
2. team A first and team B second 
3. team B first and team A second 

Input

Input consists of several datasets. Each of them has a single integer number n (1 ≤ n ≤ 1000) — the number of LPL teams.

Output

For each case, print the number of cases the ranking in the game. The result can be very large, print the result modulo 2016515.

Sample Input

1
3
1000

Sample Output

1
13
1878195
题意:问n个队伍排名,最后排名的可能情况种数。

解法:我们用a[i][j]表示当队伍数量为j个,名次种类为i种时的情况数。

我们可以分析当有j个队伍i个名次的情况是如何产生的,容易得到只能通过以下两种方式产生:

1.第j个队伍的名次是单独产生的,也就是当第j个队伍加入排名时,名次数从原来的i-1个变成了i个,这种情况的数量是  a[i-1][j-1]*i    (i-1个名次j-1个队伍,然后在i-1个名次中找一个缝插入)

2.第j个队伍的名次是本来就存在的,即这个队伍和某个或某些队伍的排名是重合的,这种情况的数量是 a[i][J-1]*i   (i个名次j-1个队伍,然后第j个队伍在i个名次中选择一个)

那么当队伍有n个的时候,排名的情况种类就是a[1][n]+a[2][n]+....+a[n][n].

所以我们可以推得a[i][j] = a[i-1][j-1] * i + a[i][j-1] * i = i * (a[i-1][j-1] + a[i][j-1])

于是n个队伍的所有排名情况即为:a[1][n]+a[2][n]+a[3][n]+....+a[n][n]


我们只需要初始化一次情况数,然后每次询问多少我们就输出多少即可。

代码:

#include<iostream>
#include<cmath>
#include<string>
using namespace std;
long long a[1002][1002]={0};
long long  c[1002]={0};
int main(){
	int i,j,k,l,n,m,t,ii;
	a[0][0]=1;
	for(i=1;i<=1000;i++)
		for(j=i;j<=1000;j++)
			a[i][j]=i*(a[i-1][j-1]+a[i][j-1])%2016515;
	for(i=1;i<=1000;i++)
		for(j=1;j<=1000;j++)
			c[i]=c[i]+a[j][i];			
	while (cin>>i)cout<<(c[i]%2016515)<<endl;	
	return 0;
}




你可能感兴趣的:(Ranking Problem)