<strong><span style= "FONT-SIZE:18PX;" > First of all, what is dynamic planning: Often hear dp:dynamic programming abbreviations Here's the entry question: the 01 backpack has a weight and value of n items of WI and VI respectively . Please select items from which to find the greatest value without the weight of a combination of W. Example: Input:n = 4 (w, v) = {(2.3), (1, 2), (3, 4), (2, 3)}w = 5outtput:7 (items selected 0, 1, 3rd) #include <iostream> #include < ;cstdio> #define MAXN 1000using namespace Std;int N, w;int W[MAXN], v[maxn];int rec (int i, int j) {int res;if (i = = N) {ret Urn res = = 0;} else if (J < W[i]) {res = rec (1 + i, j);} Else{res = max (REC (i + 1, j), REC (i + 1, j-w[i]) + v[i]);} return res;} int main () {cin >> n;for (int i = 0; i < n; i++) {cin >> w[i] >>v[i];} Cin>>w;cout<<rec (0, W) <<endl;return 0;} </span></strong>
01 Backpack--An introductory topic in dynamic planning