魔法师 (@Constanline) 在 Leetcode每日一题 —— 3742. 网格中得分最大的路径 中发帖

思路 
只能向右/下移动,那么可以用递推/动态规划。 
首先 行、列肯定要用两个维度,而花费无法直接与分数关联,所以也需要一个维度。 
代码 
class Solution {
    private static final int MIN_VAL = -1;
    public int maxPathScore(int[][] grid, int k) {
        int m = grid.length;
        int n = grid[0].length;
        // 当前行第 j 列 花费 c 的最大分数
        int[][] dp = new int[n][k + 1];
        Arrays.fill(dp[0], MIN_VAL);
        // 记录当前行的前一列的花费 和 第一列的花费
        int c...
 
 
Back to Top