[kuangbin带你飞]专题十二 基础DP1 H HDU 1260

来源:互联网 发布:淘宝畅销产品排行榜 编辑:程序博客网 时间:2024/05/17 07:25

题目地址:https://vjudge.net/contest/68966#problem/H

思路:简单DP。

AC代码:

#include<bits/stdc++.h>using namespace std;const int maxn=2000+10;int a[maxn],b[maxn],dp[maxn];int t,n;int main(){    scanf("%d",&t);    while(t--)    {        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        memset(dp,0,sizeof(dp));        scanf("%d",&n);        for(int i=1;i<=n;i++)            scanf("%d",&a[i]);        for(int i=2;i<=n;i++)            scanf("%d",&b[i]);        dp[1]=a[1];        for(int i=2;i<=n;i++)            dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);            int temp=dp[n];        int hh=temp/3600+8;        temp=temp%3600;        int mm=temp/60;        temp=temp%60;        int ss=temp;        if(hh>12)        {            printf("%02d:%02d:%02d pm\n",hh-12,mm,ss);        }        else        {             printf("%02d:%02d:%02d am\n",hh,mm,ss);        }    }}


0 0
原创粉丝点击