HDU 1260: Tickets (DP), hdu1260ticketsdp

Source: Internet
Author: User

HDU 1260: Tickets (DP), hdu1260ticketsdp

Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 923 Accepted Submission (s): 467


Problem DescriptionJesus, 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 cocould he go back home as early as possible.
A good approach, cing the total time of tickets selling, is let adjacent people buy tickets together. as the restriction of the Ticket Seller Machine, Joe can handle 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. cocould you so kind to tell poor Joe at what time cocould he go back home as early as possible? If so, I guess Joe wocould full of appreciation for your help.
 
InputThere 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 (0 s <= Si <= 25 s) representing the time consumed to buy a ticket for each person;
(K-1) integer numbers (0 s <= Di <= 50 s) representing the time needed for two adjacent people to buy two tickets together.
 
OutputFor every scenario, please tell Joe at what time cocould 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


Solution:

A person can separately buy a ticket to spend a certain amount of time, can also be two people to buy a ticket together, also given a time, give K individual separately buy a ticket time and K-1 two adjacent two people to buy a ticket together, ask the minimum time spent in total.

One [I] is the time for each individual to buy a ticket, and two [I + 1] is the time for two people to buy a ticket together.

The state transition equation is dp [I] = min (dp [I-1] + one [I], dp [I-2] + two [I]). Currently, the I-th individual can be purchased separately, but with the previous one.

Pay attention to 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 = 2000 + 50;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(two, 0, sizeof(two));        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] / 60 % 60;        int s = dp[k] % 60;        printf("%02d:%02d:%02d am\n", h, m, s);    }    return 0;}






Hdu1308 http: // acmhdueducn/showproblemphp? Pid = 1, 130


Nclude iostream>
Using namespace std;
# Define MIN (a, B) (a) (B ))? (A) :( B)
# Define MAX (a, B) (a)> (B ))? (A) :( B)
Int point [27];
Char ch [27];
Char d [5001]; // small
Char p [5001];
Int dp [2] [5001];
Int main (){
Int n, I, j, k;
While (scanf ("% d", & n )! = EOF ){
Scanf ("% s", & ch );
Int t;
For (I = 0; in; I ++ ){
Scanf ("% d", & t );
Point [ch [I]-'a'] = t;
}
Scanf ("% s", d + 1 );
Scanf ("% s", p + 1 );
Memset (dp, 0, sizeof (dp ));
Int tmp = 0;
For (I = 1; d [I]; I ++ ){
For (j = 1; p [j]; j ++ ){
If (d [I] = p [j])
Dp [tmp] [j] = dp [! Tmp] [J-1] + point [d [I]-'a'];
Else {
Dp [tmp] [j] = MAX (dp [tmp] [J-1], dp [! Tmp] [j]);
}
}
Tmp =! Tmp;
}
Coutdp [! Tmp] [J-1] endl;
}
Return 0;
}



Let's look at this question. How can I make a mistake? What is HDU's question: http: // acmhdueducn/showproblemphp? Pid = 1, 1565

Your program is not very well-thought-out from the diagonal line. If you don't talk so much about it, You can directly access the data:
3
100 1 1
1 100
200 1 1
You output 303
The correct answer should be 400.

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.