Title Link: https://leetcode.com/problems/minimum-path-sum/
Topic:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of All numbers along its path.
Note: You can only move either down or right at any point in time.
Ideas:
C[I][J] represents the minimum path from top left to i,j and the state transition equation: c[i][j]=min{c[i-1][j],c[i][j-1]}
Algorithm:
public int minpathsum (int[][] grid) { int c[][] = new Int[grid.length][grid[0].length]; C[0][0] = grid[0][0]; for (int i = 1; I <grid.length; i++) { c[i][0] = c[i-1][0]+grid[i][0]; } for (int j=1;j<grid[0].length;j++) { c[0][j] = c[0][j-1]+grid[0][j]; } for (int i = 1, i <grid.length; i++) {for (int j = 1; J <grid[0].length; J + +) { C[i][j] = math.min (c[i-1][ J], C[i][j-1]) +grid[i][j]; } } return c[grid.length-1][grid[0].length-1]; }
"Leetcode" Minimum Path Sum