总数是偶数并且其一半可得即可。
bitset的移位可替代原本的数组转移。
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <ctime> 7 #include <cctype> 8 #include <climits> 9 #include <iostream> 10 #include <iomanip> 11 #include <algorithm> 12 #include <string> 13 #include <sstream> 14 #include <stack> 15 #include <queue> 16 #include <set> 17 #include <map> 18 #include <vector> 19 #include <list> 20 #include <fstream> 21 #include <bitset> 22 #define init(a, b) memset(a, b, sizeof(a)) 23 #define rep(i, a, b) for (int i = a; i <= b; i++) 24 #define irep(i, a, b) for (int i = a; i >= b; i--) 25 using namespace std; 26 27 typedef double db; 28 typedef long long ll; 29 typedef unsigned long long ull; 30 typedef pair<int, int> P; 31 const int inf = 0x3f3f3f3f; 32 const ll INF = 1e18; 33 34 template <typename T> void read(T &x) { 35 x = 0; 36 int s = 1, c = getchar(); 37 for (; !isdigit(c); c = getchar()) 38 if (c == '-') s = -1; 39 for (; isdigit(c); c = getchar()) 40 x = x * 10 + c - 48; 41 x *= s; 42 } 43 44 template <typename T> void write(T x) { 45 if (x < 0) x = -x, putchar('-'); 46 if (x > 9) write(x / 10); 47 putchar(x % 10 + '0'); 48 } 49 50 template <typename T> void writeln(T x) { 51 write(x); 52 puts(""); 53 } 54 55 const int maxn = 2e4 + 5; 56 int a[7], sum, kase; 57 bitset<maxn> bt; 58 59 int main() { 60 while (233) { 61 sum = 0; 62 rep(i, 1, 6) read(a[i]), sum += a[i] * i; 63 if (!sum) break; 64 printf("Collection #%d: ", ++kase); 65 if (sum & 1) puts("Can't be divided. "); 66 else { 67 bt.reset(); bt.set(0); 68 rep(i, 1, 6) rep(j, 1, a[i]) bt |= bt << i; 69 if (bt.test(sum >> 1)) puts("Can be divided. "); 70 else puts("Can't be divided. "); 71 } 72 } 73 return 0; 74 }