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

UVA 12034 Race

时间:2015-01-07 23:35:22      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:


Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

 Status

Description

技术分享


  Race 

Disky and Sooma, 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, Munsiji came into their life. Munsiji took them to derby (horse racing). Munsiji enjoyed the race, but as usual Disky and Sooma 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 ( 技术分享1000), denoting the number of test cases. Each case starts with a line containing an integer n ( 1技术分享n技术分享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



Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples
Root :: Prominent Problemsetters :: Md. Mahbubul Hasan

Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Counting :: Exercises: Intermediate

 Status

技术分享

/* ***********************************************
Author        :CKboss
Created Time  :2015年01月07日 星期三 21时21分14秒
File Name     :UVA12034.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int mod = 10056;
int n;

int C[2000][2000];
int f[2000];

void init()
{
	for(int i=0;i<1100;i++) C[i][0]=C[i][i]=1;
	for(int i=2;i<1100;i++)
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	f[0]=1; f[1]=1; f[2]=3; f[3]=13;
	for(int i=4;i<=1000;i++)
	{
		int ans=0;
		for(int j=1;j<=i;j++)
		{
			ans=(ans+C[i][j]*f[i-j])%mod;
		}
		f[i]=ans;
	}
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	
	init();
	int T_T,cas=1;
	scanf("%d",&T_T);
	while(T_T--)
	{
		scanf("%d",&n);
		printf("Case %d: %d\n",cas++,f[n]);
	}
    
    return 0;
}




UVA 12034 Race

标签:

原文地址:http://blog.csdn.net/ck_boss/article/details/42507123

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