c++ - Algorithm: Maximum number I can achieve -
i got set of numbers in array. (max 110 set of numbers)
for illustration have 3 numbers in array:
5.0 , 90.0, 8.5
i have number. lets 98.6
in example.
how can determine maximum numbers can add together sum lower single number (98.6)?
in illustration can take 90.0 , 8.5 lower 98.6.
"how can determine maximum numbers can add together sum lower single number "
it's simple , sort array ( maybe using merge-sort ), contiguously add together numbers origin till sum less given number.
edited question broad:-
solution suggested above valid if want maximum numbers fall in bracket without caring how close sum given number. if care latter google "knapsack-problem".
c++ algorithm knapsack-problem
No comments:
Post a Comment