HDOJ 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): 1935 Accepted Submission (s): 933


Problem Descriptionjesus, 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.

Inputthere 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.

Outputfor every scenario, please tell Joe at-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 Input2220 254018

Sample output08:00:40 am08:00:08 am a long time did not do DP and add their own DP is very slag, the afternoon game to see people a one to make, their own can only helplessly look, alas!!! IQ AH!! Test instructions: A group of people to buy tickets, first enter each individual ticket to spend the time, in giving two people 22 combined with the time spent buying tickets to find the shortest time: the need to introduce the state transfer equation, set the array a[] is a single person to buy a ticket to spend time, array b[] is two people spend time to buy a ticket, Dp[i] Indicates the time taken by the former I individual to buy a ticket, then the state transfer equation is: Dp[i]=min (Dp[i-1]+a[i],dp[i-2]+b[i]);
#include <stdio.h> #include <string.h> #define MAX 2100#define min (x, y) (x<y?x:y) int a[max],b[max],dp[ Max];int Main () {int t,i,j,n;int h,m,s;int sum,tot;scanf ("%d", &t), while (t--) {memset (dp,0,sizeof (DP)); SCANF ("%d" , &n), for (i=1;i<=n;i++)    scanf ("%d", &a[i]), and for (i=2;i<=n;i++)    scanf ("%d", &b[i]);DP [1]=a [1];   for (i=2;i<=n;i++)     dp[i]=min (Dp[i-1]+a[i],dp[i-2]+b[i]);     printf ("%d\n", Dp[n]);   Sum=dp[n];   h=0;s=0;m=0;   s=sum%60;   M= (sum-s)/60;   if (m>=60)   {      h=h+m/60;      m=m%60;   }   H=8+h;   if (h<=12)    printf ("%02d:%02d:%02d am\n", h,m,s);   else   {    h-=12;    printf ("%02d:%02d:%02d pm\n", h,m,s);   }       

  

HDOJ 1260 Tickets "DP"

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.