2140.cpp (459B)
1 class Solution { 2 static const int size = 1E5 + 1; 3 long long dp[size]; 4 5 public: 6 Solution() { memset(dp, 0xFF, sizeof(dp)); } 7 8 long long mostPoints(const vector<vector<int>> &questions, int i = 0) { 9 if (i >= questions.size()) return 0; 10 if (dp[i] != -1) return dp[i]; 11 return dp[i] = max(questions[i][0] + mostPoints(questions, i + questions[i][1] + 1), 12 mostPoints(questions, i + 1)); 13 } 14 };