The question is a bit wordy. To put it bluntly, a maximum of S and N sets of stamps are provided. Each set has m stamps with a face value of AI, the maximum continuous nominal value and (starting from 1) can be formed when the limit is not exceeded ).
DP [N]: Minimum number of stamps that constitute I + full backpack, updating several record values
# Define n 1100int DP [N]; // minimum number of elements whose nominal value is I: int A [12] [12]; int main () {int S; while (scanf ("% d", & S) {int I, j, k; int N; scanf ("% d", & N ); int ans = min; int Index = 0; int num = max; int big = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & A [I] [0]); int M = A [I] [0]; for (j = 1; j <= m; j ++) {scanf ("% d", & A [I] [J]);} DP [0] = 0; int maxv = A [I] [m] * s; For (j = 1; j <= maxv; j ++) DP [J] = (1 <30 ); for (j = 1; j <= m; j ++) {for (k = A [I] [J]; k <= maxv; k ++) {DP [k] = min (DP [K], DP [k-A [I] [J] + 1) ;}} for (j = 1; j <= maxv; j ++) {If (DP [J]> S) break;} j --; If (j> ans) {ans = J; Index = I; num = m; big = A [I] [m];} else if (j = ans) {If (M <num) {ans = J; Index = I; num = m; big = A [I] [m];} else if (M = num) {if (a [I] [m] <big) {ans = J; Index = I; num = m; big = A [I] [m] ;}}} printf ("Max coverage = % d :", ans); for (I = 1; I <= num; I ++) {printf ("% d", a [Index] [I]);} puts ("");} return 0 ;}