剑指OFFER----面试题47. 礼物的最大价值
链接:https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/
代码
class Solution {
public:
int maxValue(vector<vector<int>>& grid) {
int m = grid.size(), n = grid[0].size();
vector<vector<int>> f(m + 1, vector<int>(n + 1));
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
f[i][j] = max(f[i - 1][j], f[i][j - 1]) + grid[i - 1][j - 1];
}
}
return f[m][n];
}
};