标签:strong log tps lint lte ram ide hal alert
This blog talks about using dynamic programming to solve the famous back pack and its variant problems.
BackPack I
Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this backpack?
You can not divide any item into small pieces.
If we have 4
items with size [2, 3, 5, 7]
, the backpack size is 11, we can select [2, 3, 5]
, so that the max size we can fill this backpack is 10
. If the backpack size is 12
. we can select [2, 3, 7]
so that we can fulfill the backpack.
You function should return the max size we can fill in the given backpack.
O(n x m) time and O(m) memory.
O(n x m) memory is also acceptable if you do not know how to optimize memory.
Given n items with size Ai and value Vi, and a backpack with size m. What‘s the maximum value can you put into the backpack?
You cannot divide item into small pieces and the total size of items you choose should smaller or equal to m.
Given 4 items with size [2, 3, 5, 7]
and value [1, 5, 2, 4]
, and a backpack with size 10
. The maximum value is 9
.
O(n x m) memory is acceptable, can you do it in O(m) memory?
[LintCode] BackPack Dynamic Programming Problems
标签:strong log tps lint lte ram ide hal alert
原文地址:http://www.cnblogs.com/lz87/p/6928227.html