hdu3127
简单DP 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3127
状态转移方程:f[i,j]=max{f[i,j],f[i-a,j]+f[a,j-b]+p,f[i,j-b]+f[i-a,b]+p}
f[i,j]=max{f[i,j],f[i-b,j]+f[b,j-a]+p,f[i,j-a]+f[i-b,a]+p}
#include
<
iostream
>
#include < algorithm >
#define max(a,b) (a>b?a:b)
using namespace std;
int test,n,x,y;
int f[ 1005 ][ 1005 ];
typedef struct
{
int len,wth,val;
} CLOTH;
CLOTH c[ 15 ];
int main()
{
scanf("%d",&test);
while(test--)
{
scanf("%d%d%d",&n,&x,&y);
for(int i=0;i<n;i++)
scanf("%d%d%d",&c[i].len,&c[i].wth,&c[i].val);
memset(f,0,sizeof(f));
for(int i=1;i<=x;i++)
for(int j=1;j<=y;j++)
{
for(int k=0;k<n;k++)
{
int a=c[k].len;
int b=c[k].wth;
if(i>=a&&j>=b)
{
f[i][j]=max(f[i][j],f[i-a][j]+f[a][j-b]+c[k].val);
f[i][j]=max(f[i][j],f[i][j-b]+f[i-a][b]+c[k].val);
}
swap(a,b);
if(i>=a&&j>=b)
{
f[i][j]=max(f[i][j],f[i-a][j]+f[a][j-b]+c[k].val);
f[i][j]=max(f[i][j],f[i][j-b]+f[i-a][b]+c[k].val);
}
}
}
printf("%d\n",f[x][y]);
}
//system("pause");
return 0;
}
#include < algorithm >
#define max(a,b) (a>b?a:b)
using namespace std;
int test,n,x,y;
int f[ 1005 ][ 1005 ];
typedef struct
{
int len,wth,val;
} CLOTH;
CLOTH c[ 15 ];
int main()
{
scanf("%d",&test);
while(test--)
{
scanf("%d%d%d",&n,&x,&y);
for(int i=0;i<n;i++)
scanf("%d%d%d",&c[i].len,&c[i].wth,&c[i].val);
memset(f,0,sizeof(f));
for(int i=1;i<=x;i++)
for(int j=1;j<=y;j++)
{
for(int k=0;k<n;k++)
{
int a=c[k].len;
int b=c[k].wth;
if(i>=a&&j>=b)
{
f[i][j]=max(f[i][j],f[i-a][j]+f[a][j-b]+c[k].val);
f[i][j]=max(f[i][j],f[i][j-b]+f[i-a][b]+c[k].val);
}
swap(a,b);
if(i>=a&&j>=b)
{
f[i][j]=max(f[i][j],f[i-a][j]+f[a][j-b]+c[k].val);
f[i][j]=max(f[i][j],f[i][j-b]+f[i-a][b]+c[k].val);
}
}
}
printf("%d\n",f[x][y]);
}
//system("pause");
return 0;
}