码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 12034 Race

时间:2014-08-15 12:51:18      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   os   io   for   ar   art   

Description

Tamim and Lina, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, e-Moti-ji came into their life. e-Moti-ji took them to derby (horse racing). e-Moti-ji enjoyed the race, but as usual Tamim and Lina did their as usual task instead of passing some romantic moments. They were thinking- in how many ways a race can finish! Who knows, maybe this is their romance!

In a race there are n horses. You have to output the number of ways the race can finish. Note that, more than one horse may get the same position. For example, 2 horses can finish in 3 ways.

 

  1. Both first
  2. horse1 first and horse2 second
  3. horse2 first and horse1 second

Input

Input starts with an integer T (bubuko.com,布布扣1000), denoting the number of test cases. Each case starts with a line containing an integer n (1bubuko.com,布布扣nbubuko.com,布布扣1000).

Output

For each case, print the case number and the number of ways the race can finish. The result can be very large, print the result modulo 10056.

Sample Input

 

3
1
2
3

Sample Output

 

Case 1: 1
Case 2: 3
Case 3: 13
题意:求n匹马可能的排列情况(可以并列)

思路:设dp[i][j]表示i匹马j个排名的情况,那么我们可以发现在dp[i-1][j]和dp[i-1][j-1]都可以在有j个插入可能

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005;
const int mod = 10056;

int n, dp[maxn][maxn];
int ans[maxn];

void init() {
	dp[0][0] = 1;
	for (int i = 1; i < maxn; i++) {
		int sum = 0;
		for (int j = 1; j <= i; j++) {
			dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) * j % mod;
			sum = (sum + dp[i][j]) % mod;
		}
		ans[i] = sum;
	}
}

int main() {
	int t, cas = 1;
	init();
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);	
		printf("Case %d: %d\n", cas++, ans[n]);
	}
	return 0;
}



UVA - 12034 Race,布布扣,bubuko.com

UVA - 12034 Race

标签:des   style   http   os   io   for   ar   art   

原文地址:http://blog.csdn.net/u011345136/article/details/38583121

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!