It means that two people collect the weights of stones together. There are six types of stones, each of which has a certain number.
Now they want to divide all the stones equally by weight. Can this be done?
This problem can be solved with multiple backpacks
Convert multiple backpacks into 01 backpacks. If DP [TOT/2] = 1, they can be evenly divided.
Otherwise, no
A large number of binary optimizations are required.
# Include <cstdio> # include <cstring> # include <cmath> # include <cstdlib> # include <iostream> # include <queue> # include <algorithm> typedef long ll; using namespace STD; int DP [1, 121000]; int main () {int A [10], CA = 1, E = 0; while (scanf ("% d ", & A [1]) {int I, j; for (I = 2; I <= 6; I ++) scanf ("% d ", & A [I]); int CNT = 0; for (I = 1; I <7; I ++) {if (a [I] = 0) CNT ++;} If (CNT = 6) break; If (E ++) printf ("\ n"); CNT = 0; For (I = 1; I <= 6; I ++) CNT + = I * A [I]; printf ("collection # % d: \ n ", CA ++); If (CNT % 2 = 1) {cout <"can't be divided. "<Endl; continue;} int ans = CNT/2; memset (DP,-1, sizeof (DP); DP [0] = 1; int K; for (I = 1; I <7; I ++) // The Rock weight is I {int tot = A [I]; // I-weight stones have tot for (j = 1; j <= tot; j * = 2) // J stones {tot-= J; for (k = ans; k> = I * j; k --) // current state {int W = I * j; If (DP [k-W]! =-1) DP [k] = 1 ;}} if (Tot! = 0) {for (k = ans; k> = I * tot; k --) {int W = I * tot; If (DP [k-W]! =-1) DP [k] = 1 ;}} if (DP [ANS] = 1) cout <"can be divided. "<Endl; else cout <" can't be divided. "<Endl;} return 0 ;}