class Solution {
public:
int minimumTotal(vector<vector<int>>& triangle) {
int rows = triangle.size();
int res;
if (rows<1){
return 0;
}
if (rows == 1){
return triangle[0][0];
}
int dp[1000][1000] = { 0 };
for (int j = 0; j < triangle[rows - 1].size(); j++){
dp[rows - 1][j] = triangle[rows - 1][j];
}
int temp = 0;
for (int i = rows - 1; i >= 1; i--){
for (int k = 0; k<triangle[i].size()-1 ; k++){
temp = min(dp[i][k], dp[i][k + 1]);
dp[i - 1][k] = temp + triangle[i - 1][k];
}
}
cout << "dp = "<<dp[0][0] << endl;
return dp[0][0];
}
};
求的是最小,一开始看错了。