传送门:

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. CountDownLatch 多线程,等待所有线程结束

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 主要方法 public CountDownLatch(int count); 构造 ...

  2. 数据库保存session

    一般情况下,php.ini里的session.save_handler默认是file,也就是用文件来保存session,这种方式有几个缺点: 1.如果单靠session自己的垃圾回收机制,时间久了,保 ...

  3. SEH结构

    首先有几点问题 1.在后文中看到的PE的节中的配置信息表Load configuration是对SEH回调函数的注册,那么Exception Table是加载的什么信息. 2.什么时候走进系统异常,什 ...

  4. IE678910不兼容H5的placeholder属性,需要JS解决

    两种方法的思路 一.使用input的value作为显示文本 二.不使用value,添加一个额外的span标签,绝对定位覆盖到input上面. 两种方式各有优缺点,方法一占用了input的value属性 ...

  5. 深入理解JavaScript系列(2):揭秘命名函数表达式

    前言 网上还没用发现有人对命名函数表达式进去重复深入的讨论,正因为如此,网上出现了各种各样的误解,本文将从原理和实践两个方面来探讨JavaScript关于命名函数表达式的优缺点. 简单的说,命名函数表 ...

  6. 抽象工厂模式&简单工厂模式

    抽象工厂模式 优点: 如IFactory factory=new AccessFactory(),在一个应用中只需要初始化一次,这就使得改变应用的时候变得非常容易:其次它让具体的创建实例过程与客户端分 ...

  7. Linux 套接字编程 - TCP连接基础

    第五章的内容,实现一个echo服务器和对应的客户端,主要收获: 0. TCP socket编程主要基本步骤 1. SIGCHLD信号含义(子进程退出时向父进程发送,提醒父进程对其状态信息进行一个获取) ...

  8. mysql四:数据操作

    一.介绍 MySQL数据操作: DML ======================================================== 在MySQL管理软件中,可以通过SQL语句中的 ...

  9. PLSQL Developer乱码

    1.select * from v$nls_parameters 查询nls的参数,获得数据库服务器端的字符编码 NLS_LANGUAGE NLS_CHARACTERSET 2.修改本地环境变量,设置 ...

  10. SharePoint 2013 - Workflow Manager

    1. Workflow Manager可以与SharePoint 安装在同一台机器上,只是不建议这么做:由于Workflow Manager 需要使用数据库,我个人将其安装在 SQL Server机器 ...