This topic is about a certain person in line to buy tickets, give everyone the time needed to buy tickets, and this person with the last person to buy tickets together with the time needed to ask all the people to purchase a ticket the minimum time required.
Because this topic is in [Kuangbin take you fly] The topic submits, therefore gives its topic link: Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68966#problem/H
Train of thought: Obviously, the time of this question has been given, then the minimum amount of time is related to the number of people who buy tickets, so we can set dp[i] to represent the minimum amount of time required to buy the last ticket with I. There are only two ways to affect the value of dp[i], one is I buy the ticket alone, at this time the dp[i]=dp[i-1]+ (I buy tickets alone); the other is I with the front one to buy tickets together, then dp[i]=dp[i-2]+ (I with the front one together buy time).
Therefore, it can be concluded that: Dp[i]=min (Dp[i],dp[i-2]+d[i]); Dp[i] initialized to dp[i]=dp[i-1]+s[i];
Code:
#include <iostream> #include <cstdio> #include <algorithm> using namespace std;
int n,k; int dp[2010],s[2010],d[2010];//Store the minimum amount of time separately, buy time, buy time//dp[i]=min (Dp[i-2]+d[i],dp[i-1]+s[i]) int main () {cin>& Gt
N
while (n--) {cin>>k;
for (int i=1;i<=k;i++) scanf ("%d", &s[i]);
for (int i=2;i<=k;i++) scanf ("%d", &d[i]);
dp[0]=0;
d[1]=0;
for (int i=1;i<=k;i++)//Enumeration endpoint if (i==1) {dp[i]=s[i];
Continue
} else{Dp[i]=dp[i-1]+s[i];
Dp[i]=min (Dp[i],dp[i-2]+d[i]);
}//cout<<dp[k]<<endl;
int h,m,s;
h=dp[k]/3600;
M= (dp[k]%3600)/60;
s=dp[k]%60;
h+=8; printf ("%02d:%02d:%02d", h>11?)
H-12:h,m,s); H>11?
printf ("pm\n"):p rintf ("am\n"); cout<