HDU 1260 Tickets (很简单的基础DP题,找到状态转移方程就直接AC了)
来源:互联网 发布:struct node什么意思 编辑:程序博客网 时间:2024/05/16 00:49
Tickets
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
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
<span style="font-family:Microsoft YaHei;font-size:18px;color:#ff0000;"><span style="line-height: 24px;">思路:d[i]表示卖完第i张票最少需要多少时间,d[i]=min(d[i-1]+a[i], d[i-2]+b[i-1])</span></span>
<span style="line-height: 24px;"><span style="font-family:Microsoft YaHei;font-size:18px;color:#ff0000;">>>AC代码:</span></span>
<span style="color: rgb(80, 84, 92); font-family: 'Open Sans', sans-serif; font-size: 16px; line-height: 24px;"></span>
//连续n人购票 每相邻两人可以一起买或者分开买,问最少时间 dp[i]=min(dp[i-2]+adj[i-1],dp[i-1]+per[i]);#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int INF=100010;int N,K;int per[2100];int adj[2100];int dp[2100];int main(){cin>>N;while(N--){memset(per,0,sizeof per);memset(adj,0,sizeof(adj));memset(dp,0,sizeof dp);cin>>K;for(int i=0;i<K;i++){cin>>per[i];}if(K==1){cout<<"08:00:";printf("%02d",per[0]);cout<<" am"<<endl;}else{for(int i=0;i<K-1;i++)cin>>adj[i];int ans=0;dp[0]=per[0];dp[1]=min(per[0]+per[1],adj[0]);for(int i=2;i<K;i++){ dp[i]=min(dp[i-1]+per[i],dp[i-2]+adj[i-1]);}int s,m,h;int t=dp[K-1];s=t%60;t=t/60;m=t%60;t=t/60;h=t;if(8+h>=12){printf("%02d:%02d:%02d pm",8+h,m,s);cout<<endl;}else{printf("%02d:%02d:%02d am",8+h,m,s);cout<<endl;}}}return 0;}
0 0
- HDU 1260 Tickets (很简单的基础DP题,找到状态转移方程就直接AC了)
- HDU 1260 Tickets(基础dp)
- hdu 1260 Tickets(基础dp)
- HDU 1260 Tickets (简单DP)
- HDU 1260 Tickets 简单DP
- hdu Tickets 1260 (简单DP)
- HDU 1260 Tickets 简单dp
- hdu 1421 dp+双状态转移方程 搬寝室
- [简单DP]Tickets HDU
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程-总结
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程
- DP问题各种模型的状态转移方程-总结
- DP问题各种模型的状态转移方程
- android的正向传值与反向传值
- Python图像库(PIL)(更新完善)
- 【BZOJ 1150】 [CTSC2007]数据备份Backup|链表|堆|贪心
- 利用jquery&iframe标签实现页面无跳转的表单文件上传
- Java学习-12天
- HDU 1260 Tickets (很简单的基础DP题,找到状态转移方程就直接AC了)
- python selenium 爬虫页面滚动条滚动到页面底部
- UIDocumentInteractionController的使用之打开和预览文档
- java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException解决办法
- 虚拟与现实的距离——VR的2016正如移动互联网的2009【下篇】
- 第八周作业里遇到的问题
- max depth exceeded when dereferencing c0-param0的问题
- [HDU 5510][2015ACM/ICPC 亚洲区沈阳站] Bazinga KMP+剪支
- 面试题--什么是线程安全和线程不安全