[PYTHON] Knapsack problem memorandum

What is the knapsack problem?

The famous NP-complete problem. The problem of putting the item in the knapsack so that the value of the item is maximized.

What is difficult?

If you think simply, it will be $ O (2 ^ N) $ because you will have to choose not to put the item in. Consider solving this in polynomial time.

We will explain how to solve these in polynomial time in three steps.

1. Image when solving

As an image of dynamic programming, consider increasing from a small state. In other words, think from one time. At one time, it is decided whether to put it in or not depending on the capacity of the knapsack. Of course, it is more valuable to put it in, so put it in. At the second time, decide whether to put it in the knapsack. What you should be careful about here is the branch with the first one in it. The decision whether to put it in the knapsack is divided. And at the third time, compare it with the knapsack at the end of the second one. In other words, it is the miso of this problem to think about whether to add a new item to the existing state.

2. Actual memory state

In production

Recommended Posts

Knapsack problem memorandum
[Python] Dynamic programming knapsack problem
Illustration of the results of the knapsack problem
Matplotlib memorandum
linux memorandum
jinja2 memorandum
Django memorandum
Command memorandum
Python Memorandum 2
plotly memorandum
Slackbot memorandum (1)
multiprocessing memorandum
Memorandum MetaTrader 5
[Linux/LPIC] Memorandum
ShellScript memorandum
pip memorandum
Python memorandum
pydoc memorandum
Probability problem
python memorandum
Pandas memorandum
python memorandum
DjangoGirls memorandum
Command memorandum
Python memorandum
pandas memorandum
python memorandum
Python memorandum
Solve the knapsack problem using pyomo and glpk
Solving the Python knapsack problem with the greedy algorithm