classSolution { public: constint N = 210; intmaxValue(vector<vector<int>>& grid){ // 先获得二维数据的长和宽 int n = grid.size(); int m = grid[0].size(); int dp[N][N]; // 从左上的(0, 0) 走到右下的(n - 1, m - 1) for (int i = 0; i < n; i ++) { for (int j = 0; j < m; j ++ ) { int t = 0; // 要处理边界的问题 if (j - 1 >= 0) t = max(t, dp[i][j - 1]); if (i - 1 >= 0) t = max(t, dp[i - 1][j]); dp[i][j] = t + grid[i][j]; } } return dp[n - 1][m - 1]; } }