HDU 1260 Tickets (很简单的基础DP题,找到状态转移方程就直接AC了)

来源:互联网 发布:struct node什么意思 编辑:程序博客网 时间:2024/05/16 00:49
  Tickets

Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u
     HDU 1260

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

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
原创粉丝点击