传送门:

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. 安装wine

    sudo add-apt-repository ppa:ubuntu-wine/ppa sudo apt-get update sudo apt-get install  winetricks

  2. Java性能调优-jstack-jstat-jmap

    0. 必须在java进程的用户下执行 a). 先排查自己业务代码,再第三方的开源代码 b). 工具类都在jdk/bin目录下, 实现代码在tools.jar中 1. jstack-线程快照-死锁/阻塞 ...

  3. Windows加密技术概述

    Windows加密是安全体系的重要基础和组成部分.现代CPU的保护模式是系统安全的硬件基石,基于CPU硬件的特权分级,Windows让自身的关键系统代码运行在高处理器特权级的内核模式,各种应用程序则运 ...

  4. artDialog组件应用学习(二)

    一.没有操作选项的对话框 预览: html前台引入代码:(之后各种效果对话框引入代码致,调用方法也一样,就不一一写入) <script type="text/javascript&qu ...

  5. openLayers3 中实现多个Overlay

    此篇的目的是为了记录下用Overlay的一些操作. 其实实现多个就是创建多个div,然后给每个div绑定Overlay. //页面加载完函数 --显示个关键点的名称 window.onload = f ...

  6. Django分页解析

    分页 django中实现管理数据分页的类位于 django.core.paginator.py中 Paginator类 对列表数据进行分页处理 对象 Paginator(Post.objects.al ...

  7. scp命令的使用

    scp命令是什么 scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令. scp命令用法 scp [-1246BCpqrv] [-c cipher ...

  8. .Net常用的命名空间

    -----------常用的命名空间--------地狱的镰刀 System.Collections //命名空间包含接口和类,这些接口和类定义各种对象(如列表.队列.位数组.哈希表和字典)的集合. ...

  9. 获取cookie信息

    随着网络安全(例如:登录安全等)要求的不断提升,越来越多的登录应用在登录时添加了验证码登录,而验证码生成算法也在不断的进化,因而对含登录态的自动化测试脚本运行造成了一定程度的困扰,目前解决此种问题的方 ...

  10. Windows 消息框架: SDK教程

    关键字:WindowsSDK 消息机制 http://www.codeproject.com/Articles/599/Windows-Message-Handling-Part-3 Handling ...