Imagine a 2D array of size
n x m, where every column is a stack of positive values. I am trying to figure out a recursive pseudo code algorithm, where I have a number
k, that is the maximum number of elements to pick from the array, which would find the indices in every column, that would maximise the sum of all the values of that index and all values above it.
[5 7 8] [2 0 1] [1 4 3]
For example here, if I took the number k to be 4 then I could only pick 4 values, s.t. the sum of them is maximised. For example, index 1 in the first column (value 2), index 0 in the second (value 7) and third column (value 8), which would result in
5 + 2 + 7 + 8
But I cannot grasp how could I implement the recursive algorithm to solve an issue like this. Would be grateful for any directions on this matter.