Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63638f5

Browse files
committed
Time: 909 ms (5.03%), Space: 141.2 MB (8.16%) - LeetHub
1 parent 7b9f2f9 commit 63638f5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Solution {
2+
public:
3+
4+
// vector<int>dp;
5+
6+
7+
long long mostPoints(vector<vector<int>>& q) {
8+
9+
//vector<int>dp(1000000,-1);
10+
// memset(dp,-1,sizeof(dp));
11+
map<long long int,long long int>dp;
12+
int i,n=q.size();
13+
for(i=n-1;i>=0;i--)
14+
{
15+
16+
if(i+q[i][1]+1<n)
17+
{
18+
dp[i]=dp[i+q[i][1]+1]+q[i][0];
19+
}
20+
else
21+
{
22+
dp[i]=q[i][0];
23+
}
24+
25+
if(i<n-1)
26+
{
27+
dp[i]=max(dp[i],dp[i+1]);
28+
}
29+
}
30+
31+
32+
33+
return dp[0];
34+
35+
}
36+
};
37+
38+
39+
/*
40+
Our dp array contains maximum points we get if we start from question i.
41+
42+
We calculate it going right to left, and the answer for position i is the maximum of:
43+
44+
Take: points[i] + dp[i + 1 + brainpower[i]],
45+
Skip: dp[i + 1].
46+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /