Min Cost Path
来源:互联网 发布:uc2监控软件账号注册 编辑:程序博客网 时间:2024/05/25 23:59
import java.util.*; class MinimumCostPath{ /* A utility function that returns minimum of 3 integers */ private static int min(int x, int y, int z) { if (x < y) return (x < z)? x : z; else return (y < z)? y : z; } private static int minCost(int cost[][], int m, int n) { int i, j; int tc[][]=new int[m+1][n+1]; tc[0][0] = cost[0][0]; /* Initialize first column of total cost(tc) array */ for (i = 1; i <= m; i++) tc[i][0] = tc[i-1][0] + cost[i][0]; /* Initialize first row of tc array */ for (j = 1; j <= n; j++) tc[0][j] = tc[0][j-1] + cost[0][j]; /* Construct rest of the tc array */ for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) tc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j]; return tc[m][n]; } /* Driver program to test above functions */ public static void main(String args[]) { int cost[][]= {{1, 2, 3}, {4, 8, 2}, {1, 5, 3}}; System.out.println("minimum cost to reach (2,2) = " + minCost(cost,2,2)); }}
阅读全文
0 0
- [DP]Min Cost Path
- Min Cost Path
- Geeks面试题:Min Cost Path
- DP6 最小路径花费 Min Cost Path @geeksforgeeks
- 动态规划之最小带权路径(Min Cost Path)
- LeetCode746. Min Cost Climbing Stairs
- 746. Min Cost Climbing Stairs
- 746. Min Cost Climbing Stairs
- 746. Min Cost Climbing Stairs
- Generate Min-Cost Tree using Kruskal
- 2 - 2 - Cost Function (8 min)
- Min Cost Climbing Stairs问题及解法
- LWC 63:746. Min Cost Climbing Stairs
- Leetcode 746. Min Cost Climbing Stairs
- LeetCode 746. Min Cost Climbing Stairs
- LeetCode#746 Min Cost Climbing Stairs (week16)
- LeetCode 746. Min Cost Climbing Stairs
- Triangle min path
- DAY8 网络设置以及 安装软件
- [LeetCode] Palindrome Partitioning I&II
- 柯洁被AlphaGo算法“玩”了,不必内疚自责
- 链表
- Sublime Text3中输入meta、img、input等标签时自动闭合问题
- Min Cost Path
- /\/\/\/\/\
- GitHub完美适配Visual Studio-03 更改
- 51Nod-1018 排序【排序】
- spring中多数据源配置
- Java多线程
- 51Nod-1179 最大的最大公约数【暴力】
- Java锁
- linux笔记