zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1289. 下降路径最小和 II | Minimum Falling Path Sum II

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/12151595.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    Given a square grid of integers arr, a falling path with non-zero shifts is a choice of exactly one element from each row of arr, such that no two elements chosen in adjacent rows are in the same column.

    Return the minimum sum of a falling path with non-zero shifts.

    Example 1:

    Input: arr = [[1,2,3],[4,5,6],[7,8,9]]
    Output: 13
    Explanation:
    The possible falling paths are:
    [1,5,9], [1,5,7], [1,6,7], [1,6,8],
    [2,4,8], [2,4,9], [2,6,7], [2,6,8],
    [3,4,8], [3,4,9], [3,5,7], [3,5,9]
    The falling path with the smallest sum is [1,5,7], so the answer is 13.
     

    Constraints:

    1 <= arr.length == arr[i].length <= 200
    -99 <= arr[i][j] <= 99


    给你一个整数方阵 arr ,定义「非零偏移下降路径」为:从 arr 数组中的每一行选择一个数字,且按顺序选出来的数字中,相邻数字不在原数组的同一列。

    请你返回非零偏移下降路径数字和的最小值。

    示例 1:

    输入:arr = [[1,2,3],[4,5,6],[7,8,9]]
    输出:13
    解释:
    所有非零偏移下降路径包括:
    [1,5,9], [1,5,7], [1,6,7], [1,6,8],
    [2,4,8], [2,4,9], [2,6,7], [2,6,8],
    [3,4,8], [3,4,9], [3,5,7], [3,5,9]
    下降路径中数字和最小的是 [1,5,7] ,所以答案是 13 。
     

    提示:

    1 <= arr.length == arr[i].length <= 200
    -99 <= arr[i][j] <= 99

  • 相关阅读:
    [YTU]_2436( C++ 习题 输出日期时间--友元类)
    [YTU]_2435 ( C++ 习题 输出日期时间--友元函数)
    病毒侵袭
    石子合并(区间DP经典例题)
    AC自动机模板2
    【模板】最近公共祖先(LCA)
    华华给月月出题
    线性筛素数
    华华开始学信息学
    华华和月月种树
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151595.html
Copyright © 2011-2022 走看看