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];
}
};
原文地址:https://blog.csdn.net/qq_45791939/article/details/145159422
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!