LightOJ - 1326 - Race(DP)
链接:
https://vjudge.net/problem/LightOJ-1326
题意:
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.
Both first
horse1 first and horse2 second
horse2 first and horse1 second
思路:
Dp[i][j] 表示一共i匹马,分成j批冲线。
Dp[i][j] = Dp[i-1][j]j+Dp[i-1][j-1]j
代码:
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 10056;
const int MAXN = 1e6+10;
int Dp[1010][1010];
int n;
void Init()
{
Dp[0][0] = 1;
for (int i = 1;i <= 1000;i++)
{
for (int j = 1;j <= i;j++)
Dp[i][j] = (Dp[i-1][j-1]*j%MOD + Dp[i-1][j]*j%MOD)%MOD;
}
}
int main()
{
// freopen("test.in", "r", stdin);
Init();
int t, cas = 0;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
printf("Case %d:", ++cas);
int ans = 0;
for (int i = 1;i <= n;i++)
ans = (ans+Dp[n][i])%MOD;
printf(" %d\n", ans);
}
return 0;
}
LightOJ - 1326 - Race(DP)的更多相关文章
- lightOJ 1326 Race(第二类Stirling数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1326 题意:有n匹马赛跑.问有多少种不同的排名结果.可以有多匹马的排名相同. 思路:排 ...
- LightOJ 1326 – Race 第二类Stirling数/
简单的模板题. 题意:问n匹马出现的不同排名数. 题解:可以使用DP,本质上还是第二类Stirling数(隔板法) #include <stdio.h> #include <iost ...
- 周赛C题 LightOJ 1047 (DP)
C - C Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description Th ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- Lightoj 1038 - Race to 1 Again (概率DP)
题目链接: Lightoj 1038 - Race to 1 Again 题目描述: 给出一个数D,每次可以选择数D的一个因子,用数D除上这个因子得到一个新的数D,为数D变为1的操作次数的期望为多少 ...
- hdu 4521 小明系列问题——小明序列(线段树 or DP)
题目链接:hdu 4521 本是 dp 的变形,却能用线段树,感觉好强大. 由于 n 有 10^5,用普通的 dp,算法时间复杂度为 O(n2),肯定会超时.所以用线段树进行优化.线段树维护的是区间内 ...
- 蓝桥杯---地宫取宝(记忆搜索=搜索+dp)
题目网址:http://lx.lanqiao.org/problem.page?gpid=T120 问题描述 X 国王有一个地宫宝库.是 n x m 个格子的矩阵.每个格子放一件宝贝.每个宝贝贴着价值 ...
- Travel(HDU 4284状压dp)
题意:给n个城市m条路的网图,pp在城市1有一定的钱,想游览这n个城市(包括1),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- redis的redisvCommand的%b
如下代码,向redis发送命令 SendCommand("HSET %b %b %b",key.data(),key.size(),filed.data(),filed.size( ...
- 常用SQL指令
SQL去重复语句:select 改为Delete select * from TRWTC01 where ITEM_NAME in (select ITEM_NAME from TRWTC01 gro ...
- 单选 textarea 赋初值
自闭合标签赋初值用$().val(),比如:<input type="text" name="text" value="123"> ...
- 深入玩转K8S之外网如何访问业务应用
有一个问题就是现在我的业务分配在多个Pod上,那么如果我某个Pod死掉岂不是业务完蛋了,当然也会有人说Pod死掉没问题啊,K8S自身机制Deployment和Controller会动态的创建和销毁Po ...
- 【题解】Luogu P5342 [TJOI2019]甲苯先生的线段树
原题传送门 挺有趣的一道题 \(c=1\),暴力求出点权和n即可 \(c=2\),先像\(c=1\)一样暴力求出点权和n,考虑有多少路径点权和也为n 考虑设x为路径的转折点,\(L\)为\(x\)向左 ...
- .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖
原文:.NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖 我们有多种工具可以将程序集合并成为一个.比如 ILMerge.Mono.Merge.前者不可定制.运 ...
- 2019 多益网络java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.多益网络等公司offer,岗位是Java后端开发,因为发展原因最终选择去了多益网络,入职一年时间了,也成为了面 ...
- 2019 易车java面试笔试题 (含面试题解析)
本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.易车等公司offer,岗位是Java后端开发,最终选择去了易车. 面试了很多家公司,感觉大部分公司考察的点都差不多 ...
- JS把格林威治时间转换为北京标准时间
function fermitTime(time){ var now = new Date(time); var year = now.getFullYear(); ; var date= now.g ...
- 140款Android开源优秀项目源码
BeautifulRefreshLayout-漂亮的美食下拉刷新 https://github.com/android-cjj/BeautifulRefreshLayout/tree/Beautifu ...