传送门:

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. [linux] uptime 命令中关于平均负载的解释

    1.当前时间 00:13:25 2.系统已运行的时间 9小时19分 3.当前在线用户 2 user 4.平均负载:0.17, 0.12, 0.07 最近1分钟.5分钟.15分钟系统的负载 为了更好地理 ...

  2. Kubernetes系列:(1) 初探

    1. 背景 在部门内容组织了一次K8s的培训,普及了下K8s的概念.框架.操作等,为便于后期查阅,也为了进一步深究K8s,因此开展K8s系列,周期不定- 2. 概念 (1) 含义:来自希腊语,意为&q ...

  3. flask-restful 请求解析

    基本参数 from flask import Flask from flask.ext.restful import reqparse, abort, Api, Resource app = Flas ...

  4. Android的存储方式

    Android常见的四种存储方式: 1. SharePreference 2. File 3. ContentProvider 4. SQLite 第一种: 保存在应用程序私有的文件夹下---- 只有 ...

  5. SQL Server Profiler(转载)

    SQL Server Profiler工具 一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收 ...

  6. 04.Path类的学习

    path 是路径的意思. path类是一个静态类,所以path是一个工具类. Path类是专门用来操作路径的. Path的常用方法: namespace _15.Path类的学习 { class Pr ...

  7. My eclipse jdk unbound的解决

    project --> properties --> java build path --> 双击出错的jdk --> alternate jre --> install ...

  8. Celery-------周期任务

    在项目目录例子的基础上进行修改一下celery文件 from celery import Celery from celery.schedules import crontab celery_task ...

  9. 16_Queue_利用wait()和notify()编写一个阻塞队列

    [线程间通信概念] 线程是操作系统中独立的个体,但这些个体如果不经过特殊的处理就不能成为一个整体,线程间的通信就成为整体必用方式之一.当线程存在通信指挥,线程间的交互性会更强大,在提高CPU利用率的同 ...

  10. 自动装配(AutoWire)

    根据 autowire 的配置选择装配策略 byName 选择和属性名 name 一致的 bean 进行装配: byType 根据类型选择,如果对应的类型匹配到多个bean,则会报错,如下配置: &l ...