标签:mini alt -- size loading class 规划 ret ++
动态规划题,根据动态规划,选择最短的路径
class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { int n = triangle.size(); vector<int> f(n); f[0] = triangle[0][0]; for (int i = 1; i < n; ++i) { f[i] = f[i - 1] + triangle[i][i]; for (int j = i - 1; j > 0; --j) { f[j] = min(f[j - 1], f[j]) + triangle[i][j]; } f[0] += triangle[i][0]; } return *min_element(f.begin(), f.end()); } };
标签:mini alt -- size loading class 规划 ret ++
原文地址:https://www.cnblogs.com/zhangdalao/p/14598782.html