0ms秒杀。。。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;
int lowbit(int t){return t&(-t);}
int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
#define LL long long
#define PI acos(-1.0)
#define N 55
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
int max(int x,int y){return x>y?x:y;}
int a[7];
int dp[250000];
int main(){
int ca=1;
int w[200];
while(scanf("%d",&a[1])){
int i,j;
int sum=a[1];
for(i=2;i<=6;i++){
scanf("%d",&a[i]);
sum+=a[i]*i;
}
if( !sum )break;
printf("Collection #%d:\n",ca++);
if( sum&1 ) {puts("Can't be divided.");puts("");}
else{
memset(dp,0,sizeof(dp));
memset(w,0,sizeof(w));
sum/=2;
int k=0;
for(i=1;i<=6;i++){ //二进制优化
if(!a[i])continue;
int t=1;
while(a[i]-t>0){
w[k++]=t*i;
a[i]-=t;
t*=2;
}
w[k++]=a[i]*i;
}
for(i=0;i<k;i++){ //01背包
for(j=sum;j>=w[i];j--){
dp[j]=max(dp[j], dp[j-w[i]]+w[i]);
}
}
if(dp[sum]!=sum)puts("Can't be divided.");
else puts("Can be divided.");
puts("");
}
}
return 0;
}