Home > Backend Development > PHP Tutorial > Find which numbers sum close to a given value (less than or equal to)

Find which numbers sum close to a given value (less than or equal to)

WBOY
Release: 2016-07-06 13:53:55
Original
1555 people have browsed it

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)

Reply content:

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 动态规划

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template