Hdu-1260:tickets

Source: Internet
Author: User
Tags ticket

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< 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.