# Include <cstdio> # include <cstring> int f [1001]; int max (int A, int B) {return (A> B? A: B);} void swap (Int & A, Int & B) // The original swap function is suspected to be incorrect. Here {int c = A; A = B; B = C;} int main () {int I, j, m, n, x, V [1001], big = 1, total, TMP; while (scanf ("% d", & M, & N )! = EOF) // two limit {memset (F, 0, sizeof (f); scanf ("% d", & X); // Total number of packages = 0; // total weight for (I = 1; I <= x; I ++) {scanf ("% d", & V [I]); if (V [I]> V [Big]) Big = I; // index mark Max total + = V [I];} swap (V [Big], V [x]); for (I = 1; I <= x; I ++) {TMP = f [m]; // TMP is used to save f [I-1, j] For (j = m; j> = V [I]; j --) // The Descending Dimension is still processed. f [J] = max (F [J-V [I] + V [I], F [J]);} // The second person does not need DP. You can directly check the sum to determine whether the removal can be performed. // you only need DP to find the maximum weight that the first person can remove, A backpack may not be filled with space. // F [I] indicates the maximum total size of a backpack with the size of I. // The value and capacity are the same, of course, you need to consider situations where the package cannot be installed. // optimize the two dimensions into one dimension, the enumeration of X objects is hidden. // Therefore, if (total-f [m]) <= N) printf ("Yes \ n") is traversed in reverse order "); // two people can remove all else if (total-V [x]-TMP) <= N) printf ("need a helper \ n "); // except for the heaviest else printf ("NO \ n");} return 0 ;}
This is still a DP, which is a simple backpack.
Because the fork assistant can move anything of weight, this strong person should consider it specially. Find the maximum weight at the end of the first time. Then he made his first backpack for 01, and then he tried to move as many items as possible, and then determined whether the remaining items could allow the second person to move. If not, determine whether the last (I .e. the largest weight) thing can be moved by the last two people.
F [I, j] indicates not to remove the maximum weight of the last one, then f [I-1, J] indicates to remove the last one.
Http://blog.sina.com.cn/s/blog_6d6add550100ypqp.html
The source of the article. The content has been corrected.