I assume that vy G and M in your problem you mean the same thing, and that you get 0 points if you do not spend any time on the exam.
In this case, I would define the DP matrix as D [i, t] = the best result achievable by spending t full units of time on a subset of exams from 0 to i.
Wlog, you can assume that the first column of the matrix is ββequal to all 0s.
In this case, you may notice that D satisfies the following repetition:
- D [0, t] = M [0, t]
- D [i, t] = max_ {0 <= k <= t} (M [i, k] + D [i-1, tk])
what you need to apply dynamic programming
source share