poj1014
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=11,M=60010,V=6001;
int i,j,k,o,s[N],sum,w[V],p,ss,q[V],g,b,tmp,n;
bool f[M],ff;
int main()
{
while (1)
{
o++;sum=p=0;
for (i=1;i<=6;i++)
{
scanf("%d",&s[i]);sum+=s[i]*i;
if (s[i]) {p++;w[p]=i;q[p]=s[i];}
}
if (sum==0) break;
printf("Collection #%d:\n",o);
if (sum%2==1) {printf("Can't be divided.\n\n");continue;}
memset(f,0,sizeof(f));sum/=2;n=p;
for (i=1;i<=n;i++)
{
g=b=1;
tmp=w[i]*2;
while (1)
{
g*=2;
if (b+g<q[i]) {p++;w[p]=tmp;}
else if (b+g==q[i]) {p++;w[p]=tmp;break;}
else {p++;b=q[i]-b;w[p]=w[i]*b;break;}
b+=g;tmp*=2;
}
}
f[0]=1;
for (i=1;i<=p;i++)
{
for (j=sum;j>=w[i];j--)
if (f[j-w[i]]) f[j]=1;
if (f[sum]) break;
}
if (f[sum]) printf("Can be divided.\n\n");
else printf("Can't be divided.\n\n");
}
return 0;
}