HDU 1260 Tickets 简单dp
来源:互联网 发布:webgame 源码下载 编辑:程序博客网 时间:2024/06/05 07:13
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): 4121 Accepted Submission(s): 2074
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.
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.
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
2220 254018
Sample Output
08:00:40 am08:00:08 am
题意:每个人都有一个买票时间,并且又给出相邻两个人的买票时间,求最少多长时间能买完票。
思路:用dp[i]存前i个人的最小花费时间。
AC代码:
#include<cstdio>#include<iostream>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>#include<string>#define LL long long#define eps 1e-8using namespace std;const int mod = 1e7+7;const int INF = 1e8;const int inf = 0x3f3f3f3f;const int maxx = 100100;const int N = 2050;int a[N];int b[N];int dp[N];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); for(int i=2; i<=n; i++) scanf("%d",&b[i]); memset(dp,0,sizeof(dp)); dp[1]=a[1]; for(int i=2; i<=n; i++) dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]); int shi=8,fen=0,miao=0; string c="am"; miao=dp[n]; fen+=miao/60; miao%=60; shi+=fen/60; fen%=60; if(shi>12) { shi-=12; c="pm"; } printf("%02d:%02d:%02d ",shi,fen,miao); cout<<c<<endl; }}
0 0
- HDU 1260 Tickets (简单DP)
- HDU 1260 Tickets 简单DP
- hdu Tickets 1260 (简单DP)
- HDU 1260 Tickets 简单dp
- [简单DP]Tickets HDU
- HDU 1260 Tickets(简单DP)
- 【HDU】-1260-Tickets(简单DP)
- hdu 1260 Tickets 【dp】
- hdu 1260 Tickets(dp)
- hdu 1260 tickets dp
- hdu 1260 Tickets dp
- HDU - 1260 Tickets(DP)
- DP-HDU-1260-Tickets
- HDU 1260 Tickets (DP)
- hdu-1260 Tickets【dp】
- HDU-1260 Tickets(DP)
- HDU-1260-Tickets【DP】
- HDU 1260 Tickets 【dp】
- Bootstrap <第一篇>
- LeetCode:Sort List
- Annotation
- Angularjs中的自定义指令
- JDBC
- HDU 1260 Tickets 简单dp
- Linux下用文件IO的方式操作GPIO(/sys/class/gpio)简单易操作
- Python:pickle模块(序列化)
- 总结
- JSON.parse()和JSON.stringify()
- 【python专题】数据集合
- 反射初步
- spring boot 配置 JPA
- 提示框--JS设置参数方法