Tickets

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

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
2
2
20 25
40
1
8
 
Sample Output
08:00:40 am 08:00:08 am

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = +;
int t[maxn];
int tt[maxn];
int dp[maxn][];
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n;
scanf("%d",&n);
for (int i=; i<=n; i++) {
scanf("%d",&t[i]);
dp[i][]=;
dp[i][]=;
}
for(int i=; i<=n; i++) {
scanf("%d",&tt[i]);
}
tt[]=t[]; dp[][]=;
dp[][]=;
for(int i=; i<=n; i++) {
dp[i][]=min(dp[i-][],dp[i-][])+t[i]; if(i>) {
dp[i][]=min(dp[i-][],dp[i-][])+tt[i];
} else {
dp[i][]=t[i];
} }
int ans = min(dp[n][], dp[n][]); int h, m, s;
h = + ans/;
ans %= ;
m = ans/;
ans %= ;
s = ans;
if(h > ) {
h %= ;
printf("%02d:%02d:%02d pm\n",h, m, s);
} else {
printf("%02d:%02d:%02d am\n",h, m, s);
} }
}

DP———6.两个状态之间的 处理的更多相关文章

  1. jQuery获取Radio选择的Value值||两个select之间option的互相添加操作(jquery实现)

    jQuery获取Radio选择的Value值: 1. $("input[name='radio_name'][checked]").val();  //选择被选中Radio的Val ...

  2. PE知识复习之PE的两种状态

    PE知识复习之PE的两种状态 一丶熟悉PE的整体结构 从下面依次网上看.可以得出PE结构 其中DOS头有DOS头结构 也就是 IMAGE_DOS_HEADER 关于结构体的各项属性.前边已经写过了.本 ...

  3. EF Core中如何正确地设置两张表之间的关联关系

    数据库 假设现在我们在SQL Server数据库中有下面两张表: Person表,代表的是一个人: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ...

  4. DP问题如何确定状态

    DP问题如何确定状态 一.dp实质 动态规划的实质就是通过小规模的同类型的问题来解决题目的问题. 所以有一个dp数组来储存所有小规模问题的解. 所以确定状态也就是缩小问题规模. 我们求解问题的一般规律 ...

  5. [转]ASP.NET MVC中的两个Action之间值的传递--TempData

    本文转自:ASP.NET MVC中的两个Action之间值的传递--TempData 一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在 ...

  6. 【SSH】——Hibernate三种状态之间的转化

    Hibernate的三种状态为:transient.persistent和detached.对这三种状态的理解可以结合Session缓存,在Session缓存中的状态为persistent,另外两种不 ...

  7. Hibernate对象状态之间的神奇转换

    状态分类 在Hibernate框架中,为了管理持久化类,Hibernate将其分为了三个状态: 瞬时态(Transient Object) 持久态(Persistent Object) 脱管态(Det ...

  8. zabbix使用fping监控任意两个节点之间的网络质量、丢包率和响应时间

    zabbix使用fping监控任意两个节点之间的网络质量.丢包率和响应时间 之前的博文 使用zabbix3..4的ICMP Ping模版实现对客户端网络状态的监控 https://www.cnblog ...

  9. DOM的小练习,两个表格之间数据的移动

    本次讲的是两个表格之间数据的移动,左边的表格移动到右边,并且左边表格移动内容消失. <head>   <meta http-equiv="Content-Type" ...

随机推荐

  1. 7-3 python操作excel

    1.写excel 写入特定单元格数据 # .导入xlwt模块 # .新建一个excel # .添加一个sheet页 # .往指定的单元格中写入数据 # .保存excel import xlwt boo ...

  2. Redhat 6.4 linux系统不重启识别热添加的硬盘方法

    1.1    选择虚拟机添加一块硬盘 1.2    查看系统当前磁盘信息 [root@zhongyi-test ~]# ls -l /dev/sd* brw-rw----. 1 root disk 8 ...

  3. angularjs处理多个$http

    本文引自:https://www.cnblogs.com/xiaojikuaipao/p/6017899.html 在实际业务中经常需要等待几个请求完成后再进行下一步操作.但angularjs中$ht ...

  4. scapy--初识

    常用的包结构: (1)OSI 5层模型 OSI中的层 功能 TCP/IP协议族 应用层 文件传输,电子邮件,文件服务,虚拟终端 TFTP,HTTP,SNMP,FTP,SMTP,DNS,Telnet 传 ...

  5. C++指针之间的赋值与转换规则总结

    C++指针之间的赋值与转换规则总结 Note:以下结论不适用于类的成员函数指针,关于类的成员函数指针会单独讨论. 一.任何类型的指针变量均可直接赋值给const void * 任何类型的非const指 ...

  6. 使用PHP生成分享图片

    小程序导航 wq.xmaht.top 假设代码中用到的资源文件夹在当前code_png目录下: /** * 分享图片生成 * @param $gData 商品数据,array * @param $co ...

  7. yii2深入理解之内核解析

    一.前言 首先,yii2最为为数不多的PHP主流开源框架,受欢迎程度不亚于laravel和TP.个人认为,研究这些框架底层代码是非常有助于自身代码编程思想的提升和代码简化程度和质量的提升的. 那么,话 ...

  8. hive 学习系列一(数据类型的定义)

    数字类型(Numeric Types) 整型 TINYINT(取值范围:-128 -- 127) SMALLINT(取值范围:-32,768 to 32,767) INT/INTEGER(取值范围: ...

  9. C语言结构体篇 结构体

    在描述一个物体的属性的时候,单一的变量类型是无法完全描述完全的.所以有了灵活的结构体变量. 结构体变量从意义上来讲是不同数据类型的组合,从内存上来讲是在一个空间内进行不同的大小划分. 1.1 结构体类 ...

  10. gcc常用命令

    1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...