题目 1282: 公交汽车

题目描述:

一个特别的单行街道在每公里处有一个汽车站。顾客根据他们乘坐汽车的公里使来付费。例如下表就是一个费用的单子。 没有一辆车子行驶超过10公里,一个顾客打算行驶n公里(1< =n< =100),它可以通过无限次的换车来完成旅程。最后要求费用最少。

代码:

java 复制代码
package lanqiao;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int [] m_v = new int[10];
        for (int i = 0; i < m_v.length; i++) {
            m_v[i] = scan.nextInt();
        }
        int N = scan.nextInt();
        scan.close();
        int[][] pg = new int [10][N+1];
        for (int i = 0; i < pg[0].length; i++) {
            pg[0][i] = i*m_v[0];
        }
        for (int i = 1; i < pg.length; i++) {
            for (int j = 0; j < pg[i].length; j++) {
                if(i+1<=j) {
                    pg[i][j] =Math.min(pg[i][j-i-1] + m_v[i], pg[i-1][j]);
                }else {
                    pg[i][j] = pg[i-1][j];
                }
            }
        }
        System.out.println(pg[9][N]);
    }
}
相关推荐
ThornArmor几秒前
奔腾的呼吸:被驱逐者的灵感
开发语言·程序人生·架构
步行cgn5 分钟前
Spring Boot 绑定嵌套 Bean 详解
java·spring boot·后端
软件黑马王子10 分钟前
12.缓存池优化:对象上限
开发语言·前端框架·c#
阿里嘎多学长11 分钟前
2026-09-07 GitHub 热点项目精选
开发语言·程序员·github·代码托管
流浪00130 分钟前
大模型技术全景(六):AI 的“逐字接龙“——Token 与自回归生成背后的真相
开发语言·人工智能·llm
Raas1001 小时前
AI网关和OpenRouter区别?MAI Gateway(魔芋企业级AI网关)企业级方案对比指南
大数据·开发语言·人工智能·gateway·php·ai网关·mai gateway
点心的游戏开发世界9 小时前
GDScript 入门笔记(十一):Lambda 与匿名函数
开发语言·笔记·游戏引擎·godot
phltxy9 小时前
C语言操作符详解
java·c语言·算法
步行cgn10 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
sunshine22 girl10 小时前
Java学习一 环境配置2 安装和基本使用Idea
java·学习·intellij-idea