The feasibility of multiple backpacks.
Meaning 1 ~ 6 stones worth 1 ~ 6. Then there are different quantities and you can ask if you can evenly distribute them to two people.
At this time, we can regard the value as a cost, and find out if we can reach half of the total value. That is to say, if the capacity of a backpack is set to half of the total value, can it be full.
It is said that there is a very powerful "cut tree" 1 ~ The minimum public factor of 6 is 60.
More than 60 ...... If (N & 1) n = 61; else n = 60;
Orz ...... I did not expect this.
# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <queue> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <cmath> # define INF 0x7fffffff # define EPS 1e-6 # define ll long longusing namespace STD; int n, m; int DP [7] [150001]; int cot [7]; int cost [7]; int main () {int cc = 1; while (1) {bool flag = 1; M = 0; For (INT I = 1; I <7; I ++) {int TMP; scanf ("% d", & TMP ); if (TMP) Flag = 0; cost [I] = I, Cot [I] = TMP; m + = cost [I] * cot [I];} If (FLAG) return 0; memset (DP,-1, sizeof (DP); printf ("collection # % d: \ n", CC ++); If (M & 1) {puts ("can't be divided. \ n "); continue;} else M/= 2; DP [0] [0] = 0; For (INT I = 1; I <7; I ++) {for (Int J = 0; j <= m; j ++) {If (DP [I-1] [J]> = 0) DP [I] [J] = cot [I]; else DP [I] [J] =-1;} For (Int J = 0; j <= m-cost [I]; j ++) {If (DP [I] [J]> 0) DP [I] [J + cost [I] = max (DP [I] [J + cost [I], DP [I] [J]-1) ;}} if (DP [6] [m] =-1) puts ("can't be divided. \ n "); else puts (" can be divided. \ n ");}}