Tickets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12331    Accepted Submission(s): 6096

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


Sample Output

:: am
:: am

题目大意与分析

有k个人,给出他们买自己的票各自需要多少时间,以及相邻两个人一块买需要多少时间,求从八点开始买,最快什么时候能卖完

状态转移方程:
    dp[i]=min(dp[i-1]+a1[i],dp[i-2]+a2[i-1]);

需要注意的是,前补零的写法:%02d

#include<bits/stdc++.h>

using namespace std;

int dp[],a1[],a2[],i,n,k,times,h,m,s;

int main()
{
cin>>n;
while(n--)
{
cin>>k;
for(i=;i<=k;i++)
{
cin>>a1[i];
}
for(i=;i<=k-;i++)
{
cin>>a2[i];
}
dp[]=a1[];
dp[]=;
for(i=;i<=k;i++)
{
dp[i]=min(dp[i-]+a1[i],dp[i-]+a2[i-]);
}
times=dp[k];
s=times%;
m=(times%)/;
h=+times/;
if(h<)
printf("%02d:%02d:%02d am\n",h,m,s);
else
printf("%02d:%02d:%02d pm\n",h-,m,s);
}
}

HDU 1260 Tickets (动态规划)的更多相关文章

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

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

  2. HDU 1260 Tickets (普通dp)

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

  3. 题解报告:hdu 1260 Tickets

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

  4. HDU 1260 Tickets(简单dp)

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

  5. hdu 1260 Tickets

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

  6. HDU - 1260 Tickets 【DP】

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

  7. HDU 1260 Tickets DP

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

  8. HDU 1260 Tickets (动规)

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

  9. HDU 1260 Tickets(基础dp)

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

随机推荐

  1. Prism框架中View与Region关联的几种方式

    Prism.Regions命名空间下有2个重要接口:IRegionManager.IRegion IRegionManager接口中的方法与属性:AddToRegion().RegisterViewW ...

  2. poi 1017 Packets 贪心+模拟

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48349   Accepted: 16392 Descrip ...

  3. HZOJ 20190727 T2 单(树上dp+乱搞?+乱推式子?+dfs?)

    考试T2,考试时想到了40pts解法,即对于求b数组,随便瞎搞一下就oxxk,求a的话,很明显的高斯消元,但考试时不会打+没开double挂成10pts(我真sb),感觉考试策略还是不够成熟,而且感觉 ...

  4. Linux 打印可变参数日志

    实现了传输进去的字符串所在的文档,函数和行数显示功能. 实现了将传入的可变参数打印到日志功能. #include<stdio.h> #include<stdarg.h> #in ...

  5. Java集合框架之简述

    Java集合框架简述 Java中的集合类是一种工具类,就像是容器,存储任意数量的具有共同属性的对象,集合框架是一个用来代表和操纵集合的统一架构,包含如下部分: 1.接口: 接口是代表集合的抽象数据类型 ...

  6. Java String字符串的不可变

    Java 通过把String类设计为final使类不可继承,将变量value设置为private并且是final的,且value没有setter方法,不可修改. 为什么这么设计: 1.字符串常量池的需 ...

  7. JVM-GC算法(一)-标记清除算法

    首先,我们得知道根搜索算法,它可以解决我们应该回收哪些对象的问题,但是它显然还不能承担垃圾搜集的重任,因为我们在程序(程序也就是指我们运行在JVM上的JAVA程序)运行期间如果想进行垃圾回收,就必须让 ...

  8. shell编程-定时删除(30天)文件

    1.创建shell touch /opt/auto-del-30-days-ago.sh chmod +x auto-del-30-days-ago.sh 2.编辑shell脚本: vi auto-d ...

  9. IDEA怎么开启终端Terminal

    方法一:在IDEA中点击view→tool window→Terminal即可开启 方法二:按住ALT+F12(如果是笔记本按不出来的话再加个Fn键)

  10. SQLite 使用主键,ROWID 及自增列

    SQLite 使用主键,ROWID 及自增列 之前关注过一些嵌入式数据库,倒时 SQLite 风头更劲,在 Android 上被应用,在 HTML5 中一些浏览器的 Local Database 的实 ...