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入门)的更多相关文章

  1. HDU 1260 Tickets (普通dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Others)   ...

  2. HDU 1260 Tickets(基础dp)

    一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...

  3. HDU 1260 Tickets(简单dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  4. 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets

    2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...

  5. HDU 1260 Tickets DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...

  6. E - Max Sum Plus Plus Plus HDU - 1244 (线性区间DP)

    题目大意:  值得注意的一点是题目要求的是这些子段之间的最大整数和.注意和Max Sum Plus Plus这个题目的区别. 题解: 线性区间DP,对每一段考虑取或者不取.定义状态dp[i][j]指的 ...

  7. 题解报告:hdu 1260 Tickets

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...

  8. HDU - 1260 Tickets 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...

  9. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...

  10. HDU 1260 Tickets (动规)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

随机推荐

  1. 深入理解那该死的BOM

    BOM(Byte Order Mark),是UTF编码方案里用于标识编码的标准标记,在UTF-16里本来是FF FE,变成UTF-8就成了EF BB BF.这个标记是可选的,因为UTF8字节没有顺序, ...

  2. C#重启IIS

    using System.Diagnostics; using System.ServiceProcess; //ServiceController sc1 = new ServiceControll ...

  3. oracle 分页其实一个子查询就好了,没理解的自然只能见样学样

    .首先rownum是一个查询缓存级别的东西,所以以下写法是错误的 ; 因为rn其实不是student表的内容,看做一个缓存编号就好 但是有些人不服了,加个a.rn<= ;结果还是不行,这下相信了 ...

  4. CPU位数、地址线位数、数据线位数、通用寄存器位数!

    CPU位数:表示的是其通用寄存器的位数,CPU的位数表示该CPU一次处理数据的最大位数. 数据线位数:是CPU的理论最大寻址空间,也是CPU与内存之间一次最大的数据传输位数. 地址线位数:是CPU实际 ...

  5. Linux的磁盘分区(二)

    LVM逻辑卷机制 PV(Physical Volume 物理卷) - 物理分区或整个物理磁盘 - 由PE(Physical Extent,基本单元)租场 VG(Volume Group 卷组) - 一 ...

  6. 安装及运行 RabbitMQ 服务器 (linux) 失败! 安装erlang 失败,无法继续

    文档 http://www.rabbitmq.com/install-rpm.html 安装前置条件 Before installing RabbitMQ, you must install Erla ...

  7. PL/SQL Developer 窥探事务

    一次登录代表一个连接 一个SQL Window 代表一个会话(session),有唯一的SID 事务(transaction) 由 insert .update 或者 delete 开启 由 comm ...

  8. Shell编程-02-Shell变量

    目录 什么是Shell变量 变量类型 环境变量初始化及其对应文件的生效顺序 什么是Shell变量     在初等数学数学方程式中,我们会经常碰到类似于这样的方程式:y=x+1 ,等号左右两边的x和y称 ...

  9. [转]ASP.NET Web API对OData的支持

    http://www.cnblogs.com/shanyou/archive/2013/06/11/3131583.html 在SOA的世界中,最重要的一个概念就是契约(contract).在云计算的 ...

  10. Spring 之 IOC

    IoC的全称是Inversion of Control,中文称为控制反转, Martin Flower由根据它创造了一个新词:Dependency Injection,中文称为依赖注入.这两个词讲的是 ...