有一堆问题,每个问题有一个得分questions[i][0],又一个brainpower值question[i][1],如果要解决这一题,可以得到该题的分数,但之后的question[i][1]道题都不能再做,问一共最多得多少分,参考了Discussion的从后往前DP
1 #2140
2 #Runtime: 1379 ms (Beats 40%)
3 #Memory: 65.1 MB (Beats 100%)
4
5 class Solution(object):
6 def mostPoints(self, questions):
7 """
8 :type questions: List[List[int]]
9 :rtype: int
10 """
11 dp = [0 for i in range(len(questions) + 1)]
12 for i in range(len(questions) -1, -1, -1):
13 p, b = questions[i]
14 dp[i] = max(p + dp[min(len(questions), i + b + 1)], dp[i + 1])
15 return dp[0]