/* Idea: first define a V [25], p [25] array to store the price and importance of the item. Define a DP [30000] (because the data cannot exceed 30000 RMB) to dynamically save each data, sum [I] = V [I] * P [I] defines the sum [] array to reduce time. The state transition equation: DP [J] = max (DP [J], DP [J-V [I] + sum [I]); */
# Include <stdio. h> # include <string. h> # define max (A, B) A> B? A: bint main () {int N; scanf ("% d", & N); While (n --) {int I, j, n, m; int V [25], p [25], DP [30000], sum [25]; memset (DP, 0, sizeof (DP); memset (v, 0, sizeof (v); memset (p, 0, sizeof (p); scanf ("% d", & N, & M); for (I = 0; I <m; I ++) {scanf ("% d", & V [I], & P [I]); // v [25], P [25] array used to store the price and importance of an item sum [I] = V [I] * P [I]; // calculate the product} for (I = 0; I <m; I ++) {for (j = N; j> = V [I]; j --) {DP [J] = max (DP [J], DP [J-V [I] + sum [I]); // The current (I + 1) is retained in each cycle DP [N) maximum number} printf ("% d \ n", DP [N]); // After the cycle is completed, the maximum number of M numbers is retained in DP [N,} return 0 ;}