HDU 1260 Tickets (普通dp)
传送门:
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
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.
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.
2
20 25
40
1
8
08:00:08 am
也可以相邻两个人一起买一张两人票,花费时间是b[i],
现在求n个人买票需要的最少时间是多少。
#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)的更多相关文章
- HDU - 1260 Tickets 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意 有N个人来买电影票 因为售票机的限制 可以同时 卖一张票 也可以同时卖两张 卖两张的话 两 ...
- 【万能的搜索,用广搜来解决DP问题】ZZNU -2046 : 生化危机 / HDU 1260:Tickets
2046 : 生化危机 时间限制:1 Sec内存限制:128 MiB提交:19答案正确:8 题目描述 当致命的T病毒从Umbrella Corporation 逃出的时候,地球上大部分的人都死去了. ...
- HDU 1260 Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1260 Tickets DP
http://acm.hdu.edu.cn/showproblem.php?pid=1260 用dp[i]表示处理到第i个的时候用时最短. 那么每一个新的i,有两个选择,第一个就是自己不和前面的组队, ...
- HDU 1260 Tickets(基础dp)
一开始我对这个题的题意理解有问题,居然超时了,我以为是区间dp,没想到是个水dp,我泪奔了.... #include<stdio.h> #include<string.h> # ...
- 题解报告:hdu 1260 Tickets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 Problem Description Jesus, what a great movie! T ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...
- hdoj 1260 Tickets【dp】
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1260 Tickets (动规)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
随机推荐
- Java自定义注解源码+原理解释(使用Java自定义注解校验bean传入参数合法性)
Java自定义注解源码+原理解释(使用Java自定义注解校验bean传入参数合法性) 前言:由于前段时间忙于写接口,在接口中需要做很多的参数校验,本着简洁.高效的原则,便写了这个小工具供自己使用(内容 ...
- LintCode刷题小记491
题目: 判断一个正整数是不是回文数. 回文数的定义是,将这个数反转之后,得到的数仍然是同一个数. 样例: 11, 121, 1, 12321 这些是回文数. 23, 32, 1232 这些不是回文数. ...
- c#-cs-bs-正则表达式
C/S B/S Cs结构: C/S(Client/Server)客户机/服务器 BS机构: B/S(Browser/Server)浏览器/服务器 à(未来发展方向) ...
- css设置文字中间的小竖线
主要css属性是border-right border-right:1px solid gray; padding-right:10px; padding-left:10px; <div dat ...
- flask-SQLAlchemy的ORM
1.创建表 import datetime from sqlalchemy import create_engine from sqlalchemy.ext.declarative import de ...
- 一个简单问题引发对IEnumerable和IQueryable的思考
问题概述: 首先看下图,有客户表和客户负责人表关系是多对多,访问数据库使用的是EF所以这里我们开启了延迟加载,需求就是将每个客户的所有负责人逗号拼接显示在负责人这一栏位, 对你没看错需求就是这么 ...
- 2.浅析Hadoop之YARN
YARN也是主从架构,主节点是ResourceManager,从节点是NodeManager,是一种资源分配及任务管理的组件 针对每个任务还有ApplicationMaster应用管理者和Contai ...
- HTML代码中<%%>、<%=%>、<%:%>
<%%>之间可以写服务器端代码 比如 <% for(var i=0;i<10;i++){%> <%=%>获取后台的变量值,比如后台一个session[&quo ...
- 集合的前N个元素
集合的前N个元素:编一个程序,按递增次序生成集合M的最小的N个数,M的定义如下: (1)数1属于M: (2)如果X属于M,则Y=2*x+1和Z=3*x+1也属于M: (3)此外 ...
- linux常用指令集-持续更新...
0.查看所有java进程GC情况:for i in `jps|egrep -v "Jps|Launcher" |cut -d" " -f1`;do pwdx $ ...