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

分析:

题目大意:
n个人比赛,排名可以并列,问有多少种情况

分析
假设n-1个人,排出了m个名次;新来1人,与前面某名次并列,有f(n-1,m)*m种结果
假设n-1个人,排出了m-1个名次;新来1人,与前面名次都不并列,有f(n-1,m-1)*m种结果
f(n,m)= f(n-1,m)*m + f(n-1,m-1)*m

code:

#include<stdio.h>
#include<algorithm>
#include<memory.h>
#include<math.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define max_v 1005
#define mod 10056
int f[max_v];
int dp[max_v][max_v];//dp[i][j]:i个人比赛 j种排名 的情况数目
int main()
{ dp[][]=;
int sum;
for(int i=;i<max_v;i++)
{
sum=;
for(int j=;j<=i;j++)
{
dp[i][j]=(dp[i-][j]+dp[i-][j-])%mod*j%mod;
sum=(sum+dp[i][j])%mod;//i个人比赛 总情况数
}
f[i]=sum;
}
int t,c=;
scanf("%d",&t);
int n;
while(t--)
{
scanf("%d",&n);
printf("Case %d: %d\n",c++,f[n]);
}
return ;
}

Race UVA - 12034(dp+打表)的更多相关文章

  1. 刷题总结——Bob's Race(hdu4123 树形dp+st表)

    题目: Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the ro ...

  2. 【bzoj5161】最长上升子序列 状压dp+打表

    题目描述 现在有一个长度为n的随机排列,求它的最长上升子序列长度的期望. 为了避免精度误差,你只需要输出答案模998244353的余数. 输入 输入只包含一个正整数n.N<=28 输出 输出只包 ...

  3. UVA 12034 Race (递推神马的)

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...

  4. UVa 12034 - Race(递推 + 杨辉三角)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVa 12034 Race 递推?

    一开始是想排列组合做的,排列组合感觉确实可以推出公式,但是复杂度嘛.. dp[i][j]表示有i只马,j个名次的方法数,显然j<=i,然后递推公式就很好写了,一只马新加进来要么与任意一个名次的马 ...

  6. UVa 12034 (递推) Race

    题意: 有n个人赛马,名次可能并列,求一共有多少种可能. 分析: 设所求为f(n),假设并列第一名有i个人,则共有C(n, i)种可能,接下来确定后面的名次,共有f(n-1)种可能 所以递推关系为: ...

  7. UVa 12034 Race (递推+组合数学)

    题意:A,B两个人比赛,名次有三种情况(并列第一,AB,BA).输入n,求n个人比赛时最后名次的可能数. 析:本来以为是数学题,排列组合,后来怎么想也不对.原来这是一个递推... 设n个人时答案为f( ...

  8. UVA 12034 Race

    https://vjudge.net/problem/UVA-12034 题意:n个人比赛,有多少种可能的结果 假设i个人中,有j个人是第一名,方案数为C(i,j) 所以ans=Σ C(n,j)* f ...

  9. UVA 12034 Race(递推)

    递推,f[i = i个名次][j = 共有j个人] = 方案数. 对于新加入的第j个人,如果并列之前的某个名次,那么i不变,有i个可供并列的名次选择,这部分是f[i][j-1]*i, 如果增加了一个名 ...

随机推荐

  1. Visual Studio Code 的使用

    常用快捷键 常用General 按 Press 功能 Function Ctrl + Shift + P,F1 显示命令面板 Show Command Palette Ctrl + P 快速打开 Qu ...

  2. 简单的CRUD(二)

    一.重构简单的CRUD 1.JDBC工具类 1.因为在crud中都包含一些相同的代码所以可以提取出来,抽取代码重构为工具类. 2.将工具类设置为static静态类,方便调用,不需要new对象. pub ...

  3. Oracle OCI操作UDT相关学习

    1.Oracle数据类型 Oracle的数据类型如下 字符串类型 char nchar varchar2 nvarchar2 数值类型 int number integer smallint 日期类型 ...

  4. aspose words做插入压缩后图片到Word文档中

    最近用aspose words做导出Word的功能,发现图片的导出有点难受,一开始是这样写的 Document doc = new Document("D:\\Template.docx&q ...

  5. csharp: DataTable export to excel,word,csv etc

    http://code.msdn.microsoft.com/office/Export-GridView-to-07c9f836 https://exporter.codeplex.com/ htt ...

  6. Storm Flow

    A Stream represents the core data model in Trident, and can be thought of as a "stream" of ...

  7. MSSQLServer——全国省份城市SQL语句

    use hr create table dbo.province ( proID int primary key, proName ), keys ) ) ,'北京市','B'); ,'天津市','T ...

  8. Maximum Subarray解题报告zz

    http://fisherlei.blogspot.com/2012/12/leetcode-maximum-subarray.html Find the contiguous subarray wi ...

  9. nginx转发配置

    nginx upstream backend19050 { server 10.10.10.10:19050 max_fails=3 fail_timeout=30s; } server { list ...

  10. sso(single sign on)

    sso系统使用 https://www.cnblogs.com/shuai-server/p/8987070.html 一:什么是sso(single sign on) ? sso(单点登录系统)简单 ...