Leetcode 2140. 解决智力问题 动态规划
原题链接:Leetcode 2140. 解决智力问题
class Solution {
public:
long long mostPoints(vector<vector<int>>& questions) {
int n = questions.size();
vector<long long> dp(n, 0);
for (int i = n - 1; i >= 0; i--) {
int a = questions[i][0];
int b = questions[i][1];
dp[i] = dp[i] + a;
if (i + 1 < n)
dp[i] = max(dp[i + 1], dp[i]);
if (i + b + 1 < n) {
dp[i] = max(dp[i], dp[i + b + 1] + a);
}
}
return dp[0];
}
};