1014

/*
多重背包问题
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int data[7];
bool DP[220000];
int main()
{
	read;
	write;
	int up,cas=1;
	while(scanf("%d %d %d %d %d %d",data+1,data+2,data+3,data+4,data+5,data+6)==6)
	{
		if(data[1]+data[2]+data[3]+data[4]+data[5]+data[6]==0)
			break;
		up = data[1]*1+data[2]*2+data[3]*3+data[4]*4+data[5]*5+data[6]*6;
		printf("Collection #%d:\n",cas++);
		if(up&1)
		{
			printf("Can't be divided.\n\n");
			continue;
		}
		memset(DP,0,sizeof(DP));
		DP[0] = 1;
		up /= 2;
		for(int i=1;i<7;i++)
		{
			int start = 1;
			while(start<data[i])
			{
				//01
				for(int j = up;j>=0;j--)
				{
					if(j-i*start<0) break;
					DP[j] = DP[j]|DP[j-i*start];
				}
				data[i]-=start;
				start*=2;
			}
			for(int j = up;j>=0;j--)
			{
				if(j-i*data[i]<0) break;
				DP[j] = DP[j]|DP[j-i*data[i]];
			}
		}
		if(DP[up])
			printf("Can be divided.\n\n");
		else
			printf("Can't be divided.\n\n");
	}
	return 0;
}
posted @ 2011-04-20 18:18  AC2012  阅读(121)  评论(0编辑  收藏  举报