HDU 1260 Tickets

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1260

The main topic: n Individuals buy tickets, everyone takes time to buy tickets, the adjacent two people can buy tickets together to save time;

So a person can buy their own tickets can also be bought with the front of the people can also buy with the people behind, and the back of the people to buy it is equivalent to the back of the people in front of the people to buy together;

Therefore, a person has two ways to buy tickets themselves or with the people in front to buy, choose the shortest time;

Get the state equation of DP:

-dp[i] = min (dp[i-1] + a[i], dp[i-2] + b[i]);

Examples:

1

5

15 5 10) 5 20

20 10 7 10

1 2 3 4 5 each person's number

(1) The time that I personally buy tickets for everyone

(2) represents the first person and the front one to buy tickets together public time

(3) The time it takes for everyone to buy their own tickets

(4) Indicates the time spent buying tickets with every two people

Each DP goes (1), the minimum value (2)

#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<stdlib.h>#defineN 2010using namespacestd;intMain () {intI, T, N, A[n], b[n], dp[n], m; scanf ("%d", &t);  while(t--)    {        intH, M, S; scanf ("%d", &N);  for(i =1; I <= N; i++) scanf ("%d", &A[i]);  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]); M=Dp[n]; H= m/3600; M= (M-h *3600) / -; S= M-h *3600M -; H+=8; if(H <= A) printf ("%02d:%02d:%02d am\n", H, M, S); Elseprintf ("%02d:%02d:%02d pm\n", H, M, S); }    return 0;}

HDU 1260 Tickets

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.