Tickets---hdu1260(简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260
题意是有n个人排队买票,第 i 个人买票所需要的时间是a[i],这个人和 i-1 或者 i+1 合买的时间是b[i];
当然每个人都要等到前面所有的人都买完了才能买,我们求所需总时间至少是多少,工作人员早上8点上班,问几点才能下班;
dp[i] 表示前i个人所发费的最小总时间,那么第i个人有两种选择自己买或者和前面的一起买(和后面一起买可以看成后面的人和他前面的人一起买)所以
dp[i] = min(dp[i-1] + a[i], dp[i-2]+b[i]);
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 2100
#define INF 0xffffff int main()
{
int T, n, a[N], b[N], dp[N];
scanf("%d", &T);
while(T--)
{
scanf("%d", &n); memset(dp, , sizeof(dp));
for(int i=;i<=n+; i++)
a[i]=b[i]=INF; for(int i=; i<=n+; i++)
scanf("%d", &a[i]);
for(int i=; i<=n+; i++)
scanf("%d", &b[i]); for(int i=; i<=n+; i++)
dp[i]=min(dp[i-]+a[i], dp[i-]+b[i]); n=n+;
int s=dp[n]%;
int m=dp[n]/%;
int h=+dp[n]/; if(h>)
printf("%02d:%02d:%02d pm\n", h-, m, s);
else
printf("%02d:%02d:%02d am\n", h, m, s);
}
return ;
}
Tickets---hdu1260(简单dp)的更多相关文章
- 【HDU - 1260 】Tickets (简单dp)
Tickets 搬中文 Descriptions: 现在有n个人要买电影票,如果知道每个人单独买票花费的时间,还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. Input 给出 N(1 ...
- HDU 1260 Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdoj1260 Tickets (简单DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 思路: 很简单的DP题,状态方程也比较容易想到,用f[i]表示到第i个人所耗的最短时间,详见代码 ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
随机推荐
- redis命令_ZADD
ZADD key score member [[score member] [score member] ...] 将一个或多个 member 元素及其 score 值加入到有序集 key 当中. 如 ...
- tail 命令详解
tail 指令 功能:从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不 ...
- ERROR C2676
直接上代码: nl.h #ifndef NL_H #define NL_H #include <iosfwd> namespace ZJ { /** Insert a newline ch ...
- PHPCMS v9.6.0后台getshell
思路来自于 http://www.cnbraid.com/2016/09/18/phpcms/ 这里自己复现了一下,自己写了一下 因为是后台的,还得登陆两次..所以不好用,主要是学习学习 漏洞来自于R ...
- sqoop从hdfs 中导出数据到mysql
bin/sqoop export \ --connect "jdbc:mysql://mini1:3306/study?useUnicode=true&characterEncodi ...
- 数据库设计(六)第二范式(2NF)?
For a table to be in the Second Normal Form, it must satisfy two conditions: The table should be in ...
- bcrypt install `node-pre-gyp install --fallback-to-build`
npm安装parse-server的过程中遇到了2次错误 尝试1 ganiks@ganiks-ubuntu-trusty-64:~$ sudo npm i -g parse-server npm WA ...
- poj2987 Firing 最大权闭合子图 边权有正有负
/** 题目:poj2987 Firing 最大权闭合子图 边权有正有负 链接:http://poj.org/problem?id=2987 题意:由于金融危机,公司要裁员,如果裁了员工x,那么x的下 ...
- pom打包参数选择
pom.xml配置 <profiles> <profile> <id>dev</id> <properties> <token> ...
- EasyUI DataGrid可编辑单元格
效果如图: 首先在需要可编辑的列上添加一个editor属性,列定义为numberbox编辑类型 <th field="SCORES" editor="{type:' ...