Chapter 3 I cannot answer the question in the first section ~~~ No way. You can only give the following question a try ~
What about this question...
First, I thought about a very silly DP equation. Let your program crash...
A two-dimensional boolean array of 10001*200 is opened, and the [denomination] [number of sheets] is used for DP. Because the maximum denomination is only 10000, the circular array method is used, barely make the space not burst, and the result goes through nine points, and 10th points have timed out decisively.
I thought about the card table later! Can be changed to one-dimensional DP! A [denomination] the minimum value is saved;
A [I] = min (a [I], a [I-denomination] + 1 );
In this way, A is good. The speed is okay.
/* ID: bysenLANG: C ++ PROG: stamps */# include <stdio. h> # define INF 0x0fffffusing namespace std; int re [10001]; // The DP array record constitutes the maximum number of stamps with the current denomination int v [201]; int min (int, int B) {return a <B? A: B;} int main () {freopen ("stamps. in "," r ", stdin); freopen (" stamps. out "," w ", stdout); int k, n; for (int I = 0; I <10001; I ++) re [I] = INF; scanf ("% d", & k, & n); for (int I = 0; I <n; I ++) {scanf ("% d ", & v [I]); re [v [I] = 1;} int top = v [0]; while (true) {top ++; if (top> 10001) re [top % 10001] = INF; for (int I = 0; I <n; I ++) if (top-v [I]> 0) re [top % 10001] = min (re [top % 10001], re [(top-v [I] + 10001) % 10001] + 1); if (re [top % 10001]> k) break;} printf ("% d \ n", top-1); return 0 ;}