POJ 1017

#include <cstdio>
#include <string.h>
int a[7];
bool isok;
int value;
int v;
int dp[100000];
#define max(x,y) ((x)>(y)?(x):(y))
void dfs(int rest,int k)
{
int i;
if(rest==0)
{
isok=true;
return;
}

else
{
if(!isok)
for(i=k;i>=1;--i)
{
if(a[i]>0)
{
if(rest-i>=0)
{
rest-=i;
a[i]--;
dfs(rest,i);
if(isok)
 break;
}
}
}
}
}


// void CompletePack(int cost,int value)
// {
// int i,j;
// for(i=cost;i<=v;++i)
// {
// dp[i]=max(dp[i],dp[i-cost]+value);
// if(dp[i]==v)
// {
// isok=true;
// return;
// }
// }
// }
// 
// void ZeroOnePack(int cost,int value)
// {
//     int i,j;
// for(i=v;i>=cost;--i)
// {
// dp[i]=max(dp[i],dp[i-cost]+value);
// if(dp[i]==v)
// {
// isok=true;
// return;
// }
// }
// }
// void MutiplePack(int cost,int value,int amount)
// {
// if(cost*amount>=v)
// {
//        CompletePack(cost,value);
//   return;
// }
// if(isok)
// return;
// int k=1;
// while(k<amount)
// {
// ZeroOnePack(k*cost,k*value);
// if(isok)
// return;
// amount-=k;
// k*=2;
// }
// ZeroOnePack(amount*cost,amount*value);
// 
// }
int  main()
{
int cases=1;
while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]))
{
int total=0;
int i,j,max=0;
isok=false;
        for(i=1;i<=6;++i)
total+=a[i]*i;
memset(dp,-1,sizeof(dp));
dp[0]=0;
if(total==0)
break;
if(total%2)
{
printf("Collection #%d:\n",cases);
printf("Can't be divided.\n\n");


}
else
{
  dfs(total/2,6);
// v=total/2;
// for(i=1;i<=6;++i)
// {
// MutiplePack(i,i,a[i]);
// if(isok)
// break;
// }
if(isok)
{
printf("Collection #%d:\n",cases);
printf("Can be divided.\n\n");


}
else
{
printf("Collection #%d:\n",cases);
printf("Can't be divided.\n\n");


}

}
cases++;


}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值