Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve 0-1 knapsack problem by PHP dynamic programming

Shulou Source: shulou.com Published: 2022-06-03 19:44:39 09月28日 Update

This article mainly shows you "how PHP dynamic planning to solve 0-1 knapsack problem", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how PHP dynamic planning to solve 0-1 knapsack problem" this article.

The specific analysis is as follows:

Description of the knapsack problem: a backpack with a maximum weight of W now has n items, each with a weight of t and a value of v.

To maximize the weight of this backpack (but not more than W), you need to maximize the value of the backpack at the same time.

Idea: define a two-dimensional array, one dimension is the number of items (representing each item), two dimensions is weight (no more than the maximum, here is 15), and the following array a

The principle of dynamic programming, the maximum value in max (opt (imurl), wi+opt (imurl)

Opt refers to the last optimal solution.

These are all the contents of the article "how PHP dynamically plans to solve the 0-1 knapsack problem". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Backpack maximum item weight dynamic planning problem value array content article principle two-dimensional learning help at the same time ideas ideas quantity easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple MariaDB MySQL Shulou Information