HDU-1260-Tickets(线性DP,DP入门)
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7996 Accepted Submission(s): 4063
Problem Description
Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
Input
There are N(1<=N<=10) different scenarios, each scenario consists of 3 lines:
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
Output
For every scenario, please tell Joe at what time could he go back home as early as possible. Every day Joe started his work at 08:00:00 am. The format of time is HH:MM:SS am|pm.
Sample Input
20 25
40
Sample Output
08:00:40 am
08:00:08 am
找到状态转移方程: dp[i] = min( dp[i-1] + a[i], dp[i-2] + b[i]); 就很容易解决问题了
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int a[2018], b[2018], dp[2018];
int i, n, k;
cin >> n;
while( n-- )
{
cin >> k;
for( i=0; i<k; i++ )
cin >> a[i];
for( i=1; i<k; i++ )
cin >> b[i];
dp[0] = a[0];
dp[1] = min( dp[0] + a[1], b[1] );
for( i=2; i<k; i++ )
dp[i] = min( dp[i-1] + a[i], dp[i-2] + b[i]);
int time = dp[k-1];
int h, m, s;
h = 8 + time / 3600;
m = time % 3600 / 60;
s = time % 60;
if( h > 12 )
{
h = h - 12;
printf("%02d:%02d:%02d pm\n", h, m, s);
}
else
printf("%02d:%02d:%02d am\n", h, m, s);
}
return 0;
}
HDU-1260-Tickets(线性DP,DP入门)的更多相关文章
- HDU 1260 Tickets (普通dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1260 Tickets(基础dp)
一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...
- HDU 1260 Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- HDU 1260 Tickets DP
http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...
- E - Max Sum Plus Plus Plus HDU - 1244 (线性区间DP)
题目大意: 值得注意的一点是题目要求的是这些子段之间的最大整数和.注意和Max Sum Plus Plus这个题目的区别. 题解: 线性区间DP,对每一段考虑取或者不取.定义状态dp[i][j]指的 ...
- 题解报告:hdu 1260 Tickets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...
- HDU - 1260 Tickets 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...
- HDU 1260 Tickets (动规)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
随机推荐
- 旋转图像 · Rotate Image
[抄题]: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockw ...
- SpringMVC框架结构的图解、架构的处理流程以及三大组件的说明和使用
1.1 框架结构 1.2 架构流程 1.用户发送请求至前端控制器DispatcherServlet: 2.DispatcherServlet收到请求调用HandlerMapping处理器映射器: 3. ...
- bug解决思路
1.定位 2.往前看3段:如果有If判断,就重点看为什么会进入到该判断里面
- std::time(0)找不到
http://zh.cppreference.com/w/cpp/chrono/c/time #include <ctime> isnan找不到 http://en.cppreferenc ...
- 全球数据库-->基金/管理产品-->分类/行业平均-->开放式分类
SecID 招募书中所定净费率 换手率% 回报日期(每日) 计价货币 回报-本月以来(每日)计价货币 回报-本季以来(每日)计价货币 回报-本年以来(每日)计价货币 回报-1日(每日)计价货币 回报- ...
- [Selenium]点击下拉框之后,从下拉列表选择元素进行点击很容易失败
点击下拉框之后,下拉列表会显示出来,但是有时候下拉列表会很快就消失掉,导致后面选择元素的时候会失败. 像这种情况,需要将鼠标移动到下拉列表上,使下拉列表维持显示,然后才选择元素进行点击. 将鼠标移动到 ...
- Java 设计模式系列(六)适配器模式
Java 设计模式系列(六)适配器模式 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作. 适配器模式的结构: 类的适配器模式 对象 ...
- 解析config文件 练手代码
解析一个如下的CONFIG文件 #config.txt #SHTTPD Web 服务器配置文件示例 #侦听端口 ListenPort = 80 #最大并发访问客户端数目 MaxClient = 8 # ...
- Oracle GoldenGate 三、加密
写在开始前 从上周开始,我花了大量的业余时间阅读GoldenGate官方文档,并根据文档实践和进一步学习了解GoldenGate,以下便是根据官方文档理解总结的GoldenGate学习内容: Orac ...
- R语言中的四类统计分布函数
R语言中提供了四类有关统计分布的函数(密度函数,累计分布函数,分位函数,随机数函数).分别在代表该分布的R函数前加上相应前缀获得(d,p,q,r).如: 1)正态分布的函数是norm,命令dnorm( ...