hdu1260(dp)

 

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260

 

分析:简单dp,dp[i]=min(dp[i-1]+a[i],dp[i-2]);

 

#include <cstdio>

#include <cstring>

#include <cmath>

#include <iostream>

#include <algorithm>

#include <queue>

#include <cstdlib>

#include <vector>

#include <set>

#include <map>

#define LL long long

#define mod 1000000007

#define inf 1<<30

#define N 2010

using namespace std;

int a[N],dp[N];

int c[N];

int main()

{

    int t,n;

    scanf("%d",&t);

    while(t--)

    {

        scanf("%d",&n);

        for(int i=1;i<=n;i++)scanf("%d",&a[i]);

        for(int i=2;i<=n;i++)scanf("%d",&c[i]);

        memset(dp,0,sizeof(dp));

        dp[1]=a[1];

        for(int i=2;i<=n;i++)dp[i]=min(dp[i-2]+c[i],dp[i-1]+a[i]);

        int sum=dp[n];

        int h=sum/3600+8;

        int m=(sum%3600)/60;

        int s=sum%60;

        printf("%02d:%02d:%02d",h,m,s);

        if(h>=12)printf(" pm\n");

        else printf(" am\n");

    }



}
View Code

 

你可能感兴趣的:(HDU)