• HDU 1260: Tickets


    2
    2
    20 25
    40
    1
    8

    08:00:40 am

    08:00:08 am

    分析:

    经典DP题目。状态转移方程:dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i])

    #include <stdio.h>
    #include <string.h>
    int min(int a,int b){
        return a>b?b:a;
    }
    int a[2005],b[2005],dp[2005];
    int main(int argc, char *argv[]) {
        int t,temp,h;
        scanf("%d",&t);
        while(t--){
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(dp,0,sizeof(dp));
            int n;
            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];
            dp[2]=min(a[1]+a[2],b[2]);
            for(int i=3;i<=n;++i)dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);
            temp=dp[n];
            h=8+temp/3600;
            printf("%02d:%02d:%02d %cm
    ",h>12?h-12:h,temp%3600/60,temp%60,h>12?'p':'a');
        }
        return 0;
    }
    View Code
  • 相关阅读:
    JavaWeb
    JavaWeb
    appium+python实现手机计算器随机计算
    使用uiautomatorviewer工具遇到以下问题-Unexpected error while obtaining UI hierarchy
    appium+python启动手机淘宝
    appium基本环境搭建
    python多个字典“合并”成一个字典
    HTML基础1-图像
    HTML基础1-文本
    RobotFrame简要安装
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9322676.html
Copyright © 2020-2023  润新知