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),到达一个城市要一定的花费,可以在城市工作赚钱,但前提有工作证(得到有一定的花费),没工作证不能在该城市工作,但可以走, ...
随机推荐
- Python输出菱形
最近准备熟悉下Python的基础语法,准备练习下输出菱形.刚好作为自己blog的开篇~~ n =10 #控制菱形的大小 for i in range(1, n): for j in range(int ...
- 1139 First Contact PAT (Advanced Level)
原题链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805344776077312 测试点分析: 首先来分析一下测试 ...
- JMeter安装及简单应用示例
一.Jmeter下载 官网地址:http://jmeter.apache.org/ 1.进入官网 2.选中一个版本下载 3.解压安装即可 二.Jmeter环境变量配置 1. 电脑桌面----> ...
- C# 获取某个时间的0点0分和23点59分59秒
C#获取当月第一天和最后一天 当月第一天0时0分0秒: DateTime.Now.AddDays( - DateTime.Now.Day).Date 当月最后一天23时59分59秒: DateTime ...
- Go内存分配器可视化指南【译】【精】
当我第一次开始尝试理解 Go 语言的内存分配器时,整个过程让我抓狂.一切看起来都像一个神秘的黑盒子.因为几乎所有技术魔法(technical wizardry)都隐藏在抽象之下,所以你需要一层一层的剥 ...
- MySQL数据库之互联网常用架构方案
一.数据库架构原则 高可用 高性能 一致性 扩展性 二.常见的架构方案 方案一:主备架构,只有主库提供读写服务,备库冗余作故障转移用 jdbc:mysql://vip:3306/xxdb 高可用分析: ...
- CNN原理
卷积神经网络(Convolutional Neural Network)的结构类似于神经网络,可以看做是对其的改进.它利用局部连接.权值共享.多核卷积.池化四个手段大大降低了参数的数目,使得网络的层数 ...
- Node: Process模块 (Features of Process)
Process模块 (Features of Process) process is a global variable which indicates the current Node.js pro ...
- quartz——JobExecutionContext和JobDataMap
控制器传值,需要根据对应值创建,启动以及对定时任务的相关操作:JobExecutionContext和JobDataMap基本用法,代码待优化,主要是用法吧第一:控制器, @RequestMappin ...
- 利用Git钩子实现代码发布
目录 1.什么是git钩子 2.安装一个钩子 3.常用的钩子脚本类型 3.1 客户端钩子 3.1.1 pre-commit 3.1.2 prepare-commit-msg 3.1.3 commit- ...