• Leetcode-931 Minimum Falling Path Sum(下降路径最小和)


     1 class Solution
     2 {
     3     public:
     4         int minFallingPathSum(vector<vector<int>>& A)
     5         {
     6             vector<vector<int>> B = A;
     7             for(int i = 0;i < A.size();i ++)
     8             {
     9                 for(int j = 0;j < A[i].size();j ++)
    10                 {
    11                     B[i][j] = A[j][i];
    12                 }
    13             }
    14             
    15             vector<vector<int>> dp = B;
    16             for(int i = B.size()-2;i >= 0;i --)
    17             {
    18                 for(int j = 0;j < B.size();j ++)
    19                 {
    20                     if(j==0)
    21                     {
    22                         dp[j][i] = min(dp[j][i+1],dp[j+1][i+1]) + B[j][i];
    23                     }
    24                     else if(j==B.size()-1)
    25                     {
    26                         dp[j][i] = min(dp[j][i+1],dp[j-1][i+1]) + B[j][i];
    27                     }
    28                     else
    29                     {
    30                         dp[j][i] = min(dp[j][i+1],min(dp[j+1][i+1],dp[j-1][i+1])) + B[j][i];
    31                     }
    32                 }
    33             }
    34             
    35             int result = 393939;
    36             for(int i = 0;i < dp.size();i ++)
    37             {
    38                 if(dp[i][0] < result)
    39                     result = dp[i][0];
    40             }
    41             return result;
    42         }
    43 };
  • 相关阅读:
    小球与盒子的故事
    2020.1.11 考试总结
    P4249 [WC2007]剪刀石头布
    P3825 [NOI2017]游戏
    BZOJ 2238 Mst
    P4240 毒瘤之神的考验
    生成函数(严重残缺)
    Min_25
    P3455 [POI2007]ZAP-Queries
    P3233 [HNOI2014]世界树
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9885269.html
Copyright © 2020-2023  润新知