Home > Article > Backend Development > Find which numbers sum close to a given value (less than or equal to)
In life, there is often a situation like this:
Online shopping, a fixed shopping coupon of 1,000 yuan, there are many products with different unit prices, 101, 230, 330, 210, 299,...
How can I use up this 1,000 yuan as much as possible.
This is just an example. I don’t know how to express it specifically when it is converted into a computer professional description.
For example: Find which numbers the sum of is close to a given value (less than or equal to)
What algorithm should be used for such a business logic? No language limit. (c,php,java,node)
In life, there is often a situation like this:
Online shopping, a fixed shopping coupon of 1,000 yuan, there are many products with different unit prices, 101, 230, 330, 210, 299,...
How can I use up this 1,000 yuan as much as possible.
This is just an example. I don’t know how to express it specifically when it is converted into a computer professional description.
For example: Find which numbers the sum of is close to a given value (less than or equal to)
What algorithm should be used for such a business logic? No language limit. (c,php,java,node)
This kind of problem belongs to the category of 背包问题
and can be solved using 贪心算法
.
01 Backpack Problem
This is a typical 01背包问题
, the most common solution is to use 动态规划