nt get_min_cost_path(vector<vector<int>>& mat) {
int rows = mat.size();
int cols = mat[0].size();
vector<int> dp(rows);
vector<int> dp_(rows);
for (int i = 0; i < rows; i++)
dp[i] = mat[i][0];
for (int c_idx = 1; c_idx < cols; c_idx++) {
for (int r_idx = 0; r_idx < rows; r_idx++) {
dp_[r_idx] = dp[r_idx];
if (r_idx != 0)
dp_[r_idx] = min(dp_[r_idx], dp[r_idx-1]);
if (r_idx != rows-1)
dp_[r_idx] = min(dp_[r_idx], dp[r_idx+1]);
dp_[r_idx] += mat[r_idx][c_idx];
}
swap(dp, dp_);
}
return *min_element(dp.begin(), dp.end());
}
10-16
6328
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)