题目链接:点击打开链接
题目给你若干数目的1,2,3,4,5,6的数目,求能不能平分。
直接套模板。。。。。哈哈哈哈哈
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int c[110],w[110],m[110],f[100010],v;
//c[]:物品所占容量;w[]物品的价值;m[]物品的数量;V为背包容量
void ZeroOnePack(int cost,int weight)//cost 为费用, weight 为价值
{
for(int i=v;i>=cost;i--)
if(f[i-cost]+weight>f[i]) f[i]=f[i-cost]+weight;
}
void CompletePack(int cost,int weight)
{
for(int i=cost;i<=v;i++)
if(f[i-cost]+weight>f[i]) f[i]=f[i-cost]+weight;
}
void MultiplePack(int cost ,int weight,int amount)
{
if(cost*amount>=v) CompletePack(cost,weight);
else
{
for(int k=1;k<amount;)
{
ZeroOnePack(k*cost,k*weight);
amount-=k;
k<<=1;
}
ZeroOnePack(amount*cost,amount*weight);
}
}
int main()
{
int i;
int ans=0;
for(i=0;i<6;i++)w[i]=c[i]=i+1;
while(scanf("%d %d %d %d %d %d",&m[0],&m[1],&m[2],&m[3],&m[4],&m[5])&&(m[0]||m[1]||m[2]||m[3]||m[4]||m[5]))
{
v=0;
for(i=0;i<6;i++)
v+=c[i]*m[i];
if(v%2)printf("Collection #%d:\nCan't be divided.\n\n",++ans);
else
{
v/=2;
memset(f,0,sizeof(f));
for(i = 0; i<6; i++)
MultiplePack(c[i],w[i],m[i]);
if(f[v]==v)printf("Collection #%d:\nCan be divided.\n\n",++ans);
else printf("Collection #%d:\nCan't be divided.\n\n",++ans);
}
}
return 0;
}