HDU 1260 Tickets

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

解题思路:

这是简单的dp。

实现代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN=10000;
int d[MAXN],s[MAXN];  //
int dp[MAXN];

/********************************************
d[i]:表示编号i+1和i+2一起买票所话费的时间
s[i]: 表示编号为i的人单度买票所花费的时间
dp[i]:表示在编号为1~i的人买票最少的花费时间。
状态转移方程是:
dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i-2])
**********************************************/


int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int K;
        scanf("%d",&K);

        for(int i=1;i<=K;i++)
            scanf("%d",&s[i]);
        for(int i=0;i<K-1;i++)
            scanf("%d",&d[i]);
        dp[0]=0;
        dp[1]=s[1];

        for(int i=2;i<=K;i++)
            dp[i]=min(dp[i-1]+s[i],dp[i-2]+d[i-2]);

        int h=(8+dp[K]/3600)%24;
        int m=(dp[K]-dp[K]/3600*3600)/60;
        int s=dp[K]%60;
        printf("%02d:%02d:%02d am
",h,m,s);
    }
}
自己选的路,跪着也要把它走完------ACM坑
原文地址:https://www.cnblogs.com/IKnowYou0/p/6604959.html