HDU 1260:tickets (DP)

Source: Internet
Author: User

Tickets Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 923 Accepted Submission (s): 467


Problem Description Jesus, what a great movie! Thousands of people is rushing to the cinema. However, the 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, are let adjacent people buy tickets together. As the restriction of the Ticket Seller machine, Joe can sell a single Ticket or both adjacent tickets at a time.
Since you is the great JESUS, you know exactly what much time needed for every person to buy a single ticket or both ticket s for him/her. Could kind to tell poor Joe at what time Could he go home as early as possible? If So, I guess Joe would full of appreciation for your help.

Input there is 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 both adjacent people to buy the tickets Togeth Er.

Output for every scenario, I. Joe at the what time could he go back home as early as possible. Every day Joe started he work at 08:00:00 am. The format of time is HH:MM:SS am|pm.

Sample Input

2 2 20 25 40 1 8
Sample Output
08:00:40 am 08:00:08 am


Problem Solving Ideas:

A person can buy tickets alone to spend a certain amount of time, you can also buy tickets two people together, also given a time, give the individual K individual ticket time and K-1 adjacent to the two people to buy tickets together time, asked the total cost of the minimum time.

Use One[i] to buy tickets for each individual time, two[i+1] for two people to buy tickets together time.

The state transition equation is: dp[i] = min (Dp[i-1]+one[i], dp[i-2] + two[i]). At present, I have two kinds of personal situation, one is to buy separately, but with the front of a piece to buy.

Also note the final output.


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

const int MAXN = + +;

int n;
int k;
int DP[MAXN];
int ONE[MAXN];
int TWO[MAXN];

int main ()
{
    scanf ("%d", &n);
    while (n--)
    {
        memset (DP, 0, sizeof (DP));
        memset (one, 0, sizeof (one));
        memset (0, sizeof ());
        scanf ("%d", &k);
        for (int i=1; i<=k; i++) scanf ("%d", &one[i]);
        for (int i=2; i<=k; i++) scanf ("%d", &two[i]);
        Dp[0] = 0;dp[1] = one[1];
        for (int i=2; i<=k; i++) Dp[i] = min (Dp[i-1]+one[i], dp[i-2]+two[i]);
        int h = dp[k]/3600 + 8;
        int m = dp[k]/%;
        int s = dp[k]%;
        printf ("%02d:%02d:%02d am\n", H, M, s);
    }

    return 0;
}





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.