总数是偶数并且其一半可得即可。
bitset的移位可替代原本的数组转移。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#include <bitset>
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; template <typename T> void read(T &x) {
x = ;
int s = , c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') s = -;
for (; isdigit(c); c = getchar())
x = x * + c - ;
x *= s;
} template <typename T> void write(T x) {
if (x < ) x = -x, putchar('-');
if (x > ) write(x / );
putchar(x % + '');
} template <typename T> void writeln(T x) {
write(x);
puts("");
} const int maxn = 2e4 + ;
int a[], sum, kase;
bitset<maxn> bt; int main() {
while () {
sum = ;
rep(i, , ) read(a[i]), sum += a[i] * i;
if (!sum) break;
printf("Collection #%d:\n", ++kase);
if (sum & ) puts("Can't be divided.\n");
else {
bt.reset(); bt.set();
rep(i, , ) rep(j, , a[i]) bt |= bt << i;
if (bt.test(sum >> )) puts("Can be divided.\n");
else puts("Can't be divided.\n");
}
}
return ;
}