动态规划题,根据动态规划,选择最短的路径
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()); } };