public int maxValue(int[][] grid) {
int row = grid.length;
int colum = grid[0].length;
int dp[][] = new int[row+1][colum+1];
for (int i = 1; i < row+1; i++) {
for (int j = 1; j < colum+1; j++) {
dp[i][j] = Math.max(dp[i][j-1],dp[i-1][j]) + grid[i - 1][j - 1];
}
}
return dp[row][colum];
}
剑指 Offer 47. 礼物的最大价值(dp)
最新推荐文章于 2024-08-20 10:34:34 发布