I am trying to solve a problem:
Given an
N
xM
matrix, each element represents the cost associated to buy an item. Given that we plan to buyM-1
items from each of theN
rows, what is the minimum amount that we would have to spend, if we plan to buy items of allM
types?
For e.g., if the input is:
2 3 5
3 2 5
4 4 7
the output should be: (2+3) + (2+5) + (4+4) = $20.
I am confused if this is DP or greedy.
I feel it is greedy, since we have to buy M-1
items. So, for each of the three columns in the above example, we could just select the lowest value (2
, 2
and 5
) and use that towards the calculation of the final result. I considered a few more examples and this logic seems to work, but I do not feel 'confident' about it. I am unable to 'prove' it. Could someone please confirm if I am on the right track?