传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1260

Tickets

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

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
 
Source
 
题目意思:
    题意:有n个人买票,可以一人买一张,花费时间是a[i],
    也可以相邻两个人一起买一张两人票,花费时间是b[i],
    现在求n个人买票需要的最少时间是多少。
分析:
dp[i]:代表第i个人买好票需要的时间
  dp方程:
 dp[ i ] = min { dp[ i-1 ] + a[ i ] , dp[ i-2 ] + b[ i ] };
对当前人的来说两种选择:就是买一张:dp[ i-1 ] + a[ i ]
或者当前人和前面人一起买(买两张:dp[ i-2 ] + b[ i ]
然后从二种选择里面选出最小的
 
code:
#include<bits/stdc++.h>
using namespace std;
#define max_v 2005
int a[max_v];
int b[max_v];
int dp[max_v];
int main()
{
/*
题意:有n个人买票,可以一人买一张,花费时间是a[i],
也可以相邻两个人一起买一张两人票,花费时间是b[i],
现在求n个人买票需要的最少时间是多少。
分析:
dp[ i ] = min { dp[ i-1 ] + a[ i ] , dp[ i-2 ] + b[ i ] };
*/
int t,n;
int h,f,s;
cin>>t;
while(t--)
{
memset(dp,,sizeof(dp));
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
for(int i=;i<=n;i++)
{
cin>>b[i];
}
dp[]=;
dp[]=a[];
for(int i=;i<=n;i++)
{
dp[i]=min(dp[i-]+a[i],dp[i-]+b[i]);
}
s=dp[n]%;
f=dp[n]/%;
h=dp[n]//;
h+=;
h%=;
if(h>)
{
h-=;
printf("%02d:%02d:%02d pm\n",h,f,s);
}else
{
printf("%02d:%02d:%02d am\n",h,f,s);
} }
return ;
}

HDU 1260 Tickets (普通dp)的更多相关文章

  1. HDU - 1260 Tickets 【DP】

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

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

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

  3. HDU 1260 Tickets(简单dp)

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

  4. HDU 1260 Tickets DP

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

  5. HDU 1260 Tickets(基础dp)

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

  6. 题解报告:hdu 1260 Tickets

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

  7. hdu 1260 Tickets

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

  8. hdoj 1260 Tickets【dp】

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

  9. HDU 1260 Tickets (动规)

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

随机推荐

  1. android应用签名详解

    1.Eclipse工程中右键工程,弹出选项中选择 android工具-生成签名应用包: 2.选择需要打包的android项目工程: 3.如果已有私钥文件,选择私钥文件 输入密码,如果没有私钥文件见 第 ...

  2. HDU 5313——Bipartite Graph——————【二分图+dp+bitset优化】

    Bipartite Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. 【Xshell】设置XShell最大的显示行数

    选择会话,依次点击“文件"->"属性”,打开“会话属性”窗体   在“会话属性”窗体中,选择“终端”,下图中红框标注的地方是“缓冲区大小”,修改其中的值,其范围在0~2,14 ...

  4. SpringSecurity 3.2入门(8)自定义权限控制数据库设计

    ; -- ---------------------------- -- Table structure for t_system_authority_info -- ---------------- ...

  5. Java开发团队管理细则

    软件开发是团队协作,多人开发很容易造成协调问题,因此,做一些必要的开发规范,有助于帮助新员工成长,也有助于提高开发效率,防止各种问题影响开发进度. 1. 代码规范 建议每位java开发人员都读一下&l ...

  6. spring集成JPA的三种方法配置

    JPA是Java EE5规范之一,是一个orm规范,由厂商来实现该规范.目前有hibernate,OpenJPA,TopLink和EclipseJPA等实现 spring提供三种方法集成JPA:1.L ...

  7. ef linq 查询某时间段内数据 踩的坑

    var now = DateTime.Now;var list =db.Jinbi_TypeLimit.Where(x => x.IsAvailable && x.JinbiTy ...

  8. WSAAsyncSelect 消息模型

    select 模型虽然可以管理多个socket,但是它涉及到一个时机的问题,select模型会针对所管理的数组中的每一个socket循环检测它管理是否在对应的数组中,从时间复杂度上来说它是O(n^2) ...

  9. sass函数:@function

    sass定义了很多函数可供使用,当然你也可以自己定义函数,以@fuction开始. sass的官方函数链接为:sass fuction,实际项目中我们使用最多的应该是颜色函数,而颜色函数中又以ligh ...

  10. pdf转为html查看pdf.js

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...