Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve multiple knapsack problems in C language dynamic programming

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of C language dynamic planning how to solve a variety of knapsack problems, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that after reading this article on how to solve a variety of knapsack problems in C language dynamic planning, we will gain something. Let's take a look.

01 knapsack problem

Detailed explanation of C language Mathematical problem and simple DP01 knapsack problem

Recall this picture first.

Here I will send the 01 knapsack problem code again, which can be used for comparison.

2D:

# includeusing namespace std;const int MAXN = 1005 int int v [MAXN]; / / Volume int w [MAXN]; / / value int f [MAXN] [MAXN]; / / f [I] [j], maximum value of the first I items under j volume int main () {int n, m; cin > n > m; for (int I = 1; I > v [I] > > w [I]; for (int I = 1; I m For (int I = 1; I > v > > w; / input while processing for (int j = m; j > = v; JML -) f [j] = max (f [j], f [j-v] + w);} cout n > > m; for (int I = 1; I > v [I] > w [I]; for (int I = 1; i m; ll aline bc) For (ll iTunes 1 [I] > a > b > > c; for (ll js [I]); for (int juniors j > v [I] [j] > > w [I] [j]); / / read} for (int iridges 1 [iv] [j] > > w [I] [j];}} for (int itimulties 0 / 10 / 0 / 10) {for (int / I / 0 / 1) KMQ -) can also if (j > = v [I] [k]) f [j] = max (f [j], f [JQ v [I] [k]] + w [I] [k]);}} cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report