HDU 1260 Tickets

Source: Internet
Author: User

The formula is very simple, that is, the initial value should be handled well.

#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;const int inf=9999999; int S[2005],d[2005],dp[2005][2];//dp[i][0] The number of the first I is processed independently, the maximum value of the number of previous I dp[i][1] The number of first I and the preceding number, the maximum value of the previous I number int main () {#ifndef Online_judgefreopen ("In.txt", "R", stdin), #endifint t,n;scanf ("%d", &t), while (t--) {scanf ("%d", &n); for (int i =1;i<=n;i++) {Dp[i][0]=inf;dp[i][1]=inf;} for (int i=1;i<=n;i++) scanf ("%d", &s[i]), and for (int i=2;i<=n;i++) scanf ("%d", &d[i]);DP [1][0]=s[1]; DP[1][1]=S[1];DP [0][0]=0;dp[0][1]=0;for (int i=2;i<=n;i++) {dp[i][0]=min (dp[i-1][1],dp[i-1][0]) +s[i];DP [i][1]= Min (dp[i-2][0],dp[i-2][1]) +d[i];} int ans=min (dp[n][0],dp[n][1]); int H,m,s;h=ans/3600;ans=ans%3600;m=ans/60;ans=ans%60;s=ans;int flag=0;if (8+h>= {flag=1;h-=12;} if (8+h<10) printf ("0%d:", 8+h), Else printf ("%d:", 8+h), if (m<10) printf ("0");p rintf ("%d:", m); if (s<10) printf ("0"), if (flag==0) printf ("%d am\n", s), Else printf ("%d pm\n", s);}}


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.