Exercise Web site: http://poj.org/problem? Id = 3624
Question Analysis: this type of question limits the total quantity and total quality of the item, and initializes the initial quality and a quantified nature of each item. Finally, we can solve the problem of how many values are quantified.
This type of problem can be solved through: the optimal solution of the parent problem depends on the optimal solution of some sub-problems. This is the so-called optimal sub-structure.
Core Idea: dp (I, j) = max {dp (I-1, J), DP (I-1, J-CI) + wi}
AC code analysis:
# include
# include
# include
# include
using namespace STD;
int bag [12900]; // backpack
int W [3410], V [3410]; // two attributes
int main ()
{< br> int n, m;
CIN >>n> m; // initial quantity and Specified Quality
for (INT I = 1; I <= N; I ++) // This is exactly two arrays
CIN> W [I]> V [I]; // all input is completed
// memset (bag, 0, sizeof (BAG); this statement is mainly used to clean up a small number of functions can not be used
for (INT I = 1; I <= N; I ++)
for (int K = m; k> = W [I]; k --)
If (BAG [k-W [I] + V [I]> bag [k]) // process of finding two maximum values
bag [k] = bag [k-W [I] + V [I];
cout return 0;
}