zoukankan      html  css  js  c++  java
  • Uva 12034 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  

    简单DP。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    int dp[1100][1100];
    int ans[1100];
    void f()
    {
    	memset(dp, 0, sizeof(dp));
    	memset(ans, 0, sizeof(ans));
    	dp[0][0] = 1;
    	for (int i = 1; i <= 1000; i++)
    	{
    		int sum = 0;
    		for (int j = 1; j <= i; j++)
    		{
    			dp[i][j] += (dp[i - 1][j] + dp[i - 1][j - 1]) % 10056 * j % 10056;
    			sum = (sum % 10056 + dp[i][j]) % 10056;
    		}
    		ans[i] = sum;
    	}
    }
    int main()
    {
    
    	int n, t;
    	int cas = 1;
    	f();
    	scanf("%d", &t);
    	while (t--)
    	{
    		scanf("%d", &n);
    		printf("Case %d: %d
    ", cas++, ans[n]);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    json对象字符串互转
    git stash压栈
    Array、ArrayList和List三者的区别
    弱类型dynamic与var
    使用git初始化项目
    git本地分支关联远程分支
    mysql索引
    js中 var functionName = function() {} 和 function functionName() {} 两种函数声明的区别
    深入理解JavaScript中的this关键字
    c#读取xml文件
  • 原文地址:https://www.cnblogs.com/csushl/p/9409260.html
Copyright © 2011-2022 走看看