标签:art acm str blank ... use col content int
http://acm.hdu.edu.cn/showproblem.php?pid=1059
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29901 Accepted Submission(s): 8501
#include<bits/stdc++.h>
using namespace std;
#define max_v 120000
#define max_n 7
int num[max_n],f[max_v],v[max_n]={0,1,2,3,4,5,6};
void ZeroOnePack(int cost,int weight,int c)
{
for(int v=c;v>=cost;v--)
{
f[v]=max(f[v],f[v-cost]+weight);
}
}
void CompletePack(int cost,int weight,int c)
{
for(int v=cost;v<=c;v++)
{
f[v]=max(f[v],f[v-cost]+weight);
}
}
void MultiplePack(int cost,int weight,int amount,int c)
{
if(cost*amount>=c)
{
CompletePack(cost,weight,c);
return ;
}
int k=1;
while(k<amount)
{
ZeroOnePack(k*cost,k*weight,c);
amount-=k;
k*=2;
}
ZeroOnePack(amount*cost,amount*weight,c);
}
int main()
{
int t=0;
while(1)
{
int sum=0,flag=0;
for(int i=1;i<max_n;i++)
{
scanf("%d",&num[i]);
sum=sum+i*num[i];
}
if(sum==0)
break;
if(sum%2==1)
{
printf("Collection #%d:\nCan‘t be divided.\n\n",++t);
continue;
}
sum=sum/2;
memset(f,0,sizeof(f));
for(int i=1;i<max_n;i++)
{
MultiplePack(v[i],v[i],num[i],sum);
}
//printf("%d\n",f[sum]);
if(f[sum]==sum)
{
flag=1;
}
if(flag==1)
{
printf("Collection #%d:\nCan be divided.\n\n",++t);
}else
{
printf("Collection #%d:\nCan‘t be divided.\n\n",++t);
}
}
return 0;
}
标签:art acm str blank ... use col content int
原文地址:https://www.cnblogs.com/yinbiao/p/9141505.html