vendredi 28 juin 2019

Need help in writing dynamic programming code

I have a problem of dynamic programming where i know dp would be applied but i am not able to come up with optimal code.

The problem goes like this say i have 7 unique numbers in an array. say 1,2,3,4,5,6,7 are my numbers. I want to combine these numbers into two sets of (3,4) elements or (2,5) elements or (1,6) elements such that the count is maximum . The count i am calculating in a bottom up manner from similar such sets. To clarify further

(1,2) has own count (2,3) will have a own count , similarly (1,3,4) will have a count and so will (1,5,6,7) while building bottom up . Now my goal is to combine the 7 numbers from 2 sets so that the sum of counts is maximum i.e. if (1,4,6,7) has a count 2000 and (2,3,5) 1000 and (1,2,3,4) has a count 1500 and (5,6,7) has a count 500.

My final solution should have (1,4,6,7) and (2,3,5) since the sum if maximum.

Quick help is highly appreciated , please ask me if any further clarification is required. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire