hdu 3127 WHUgirls

来源:互联网 发布:淘宝上怎么注册开店 编辑:程序博客网 时间:2024/05/27 09:45

http://acm.hdu.edu.cn/showproblem.php?pid=3127

题意:用规定大小的布裁给出的布,获得最大利润,可以不完全用完布,二维完全背包

分化方案:


#include<iostream>
#include<cstdio>
using namespace std;
int f[1002][1002];
struct CLOTH
{
int x,y,vau;
}cloth[15];


int max(int x,int y)
{
return x>y?x:y;
}


int main()
{
int T,N,X1,Y1,i,j,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&N,&X1,&Y1);
for(i=0;i<N;i++)
scanf("%d%d%d",&cloth[i].x,&cloth[i].y,&cloth[i].vau);
memset(f,0,sizeof(f));
for(i=0;i<=X1;i++)
{
for(j=0;j<=Y1;j++)
{
for(k=0;k<N;k++)//放到内层循环
{
if(i>=cloth[k].x&&j>=cloth[k].y)
f[i][j]=max(f[i][j],max(f[i-cloth[k].x][j]+f[cloth[k].x][j-cloth[k].y]+cloth[k].vau,f[i][j-cloth[k].y]+f[i-cloth[k].x][cloth[k].y]+cloth[k].vau)); 
if(j>=cloth[k].x&&i>=cloth[k].y)
f[i][j]=max(f[i][j],max(f[i-cloth[k].y][j]+f[cloth[k].y][j-cloth[k].x]+cloth[k].vau,f[i][j-cloth[k].x]+f[i-cloth[k].y][cloth[k].x]+cloth[k].vau));
}
}
}
printf("%d\n",f[X1][Y1]);
}
return 0;
}

原创粉丝点击