Q: I can buy goods with a banknote With a denomination of N, because the store does not change to zero, so I need the minimum "waste.
Idea: This question is a typical full backpack question (you can also solve it in other ways). 150,200,350 is used as the volume of the object, and N is used as the volume of the backpack.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Define N 11111
Int type [4] = {0,150,200,350}, w [N];
Int main ()
{
Int t, n, I, j;
While (scanf ("% d", & t) = 1)
{
While (t --)
{
Scanf ("% d", & n );
Memset (w, 0, sizeof (w ));
For (I = 1; I <= 3; I ++) // indicates that this item has or does not exist (01 backpack)
{
For (j = type [I]; j <= n; j ++) // Note: This is different from the 01 backpack. for the reason, refer to the backpack 9 lecture (second edition)
{
If (w [j] <w [j-type [I] + type [I])
W [j] = w [j-type [I] + type [I];
}
}
Printf ("% d \ n", n-w [n]);
}
}
Return 0;
}
Author: sdc1992