WHUgirls

#描述
There are many pretty girls in Wuhan University, and as we know, every girl loves pretty clothes, so do they. One day some of them got a huge rectangular cloth and they want to cut it into small rectangular pieces to make scarves. But different girls like different style, and they voted each style a price wrote down on a list. They have a machine which can cut one cloth into exactly two smaller rectangular pieces horizontally or vertically, and ask you to use this machine to cut the original huge cloth into pieces appeared in the list. Girls wish to get the highest profit from the small pieces after cutting, so you need to find out a best cutting strategy. You are free to make as many scarves of a given style as you wish, or none if desired. Of course, the girls do not require you to use all the cloth.
#INPUT
The first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of three integers N, X, Y, N indicating there are N kinds of rectangular that you can cut in and made to scarves; X, Y indicating the dimension of the original cloth. The next N lines, each line consists of two integers, xi, yi, ci, indicating the dimension and the price of the ith rectangular piece cloth you can cut in.
#OUTPUT
Output the maximum sum of prices that you can get on a single line for each case.

Constrains
0 < T <= 20
0 <= N <= 10; 0 < X, Y <= 1000
0 < xi <= X; 0 < yi <= Y; 0 <= ci <= 1000

#Sample INPUT
1
2 4 4
2 2 2
3 3 9
#Sample OUTPUT
9
#分析:
http://blog.csdn.net/u013480600/article/details/40512311

#include<iostream>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const int Max=1e3+5;
int n,x,y;
int dp[Max][Max];
struct rectangle
{
	int xi;
	int yi;
	int val;
}p[15];
void input()
{
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i].xi>>p[i].yi>>p[i].val;
	}
}
void solve()
{
	memset(dp,0,sizeof(dp));
	for(int i=0;i<=x;i++)
	for(int j=0;j<=y;j++)
	for(int k=1;k<=n;k++)
	{
		if(i>=p[k].xi && j>=p[k].yi)
		{
			dp[i][j]=max(dp[i][j],max(dp[i-p[k].xi][j]+dp[p[k].xi][j-p[k].yi],dp[i-p[k].xi][p[k].yi]+dp[i][j-p[k].yi])+p[k].val);
		}
		if(i>=p[k].yi && j>=p[k].xi)
		{
			dp[i][j]=max(dp[i][j],max(dp[p[k].yi][j-p[k].xi]+dp[i-p[k].yi][j],dp[i-p[k].yi][p[k].xi]+dp[i][j-p[k].xi])+p[k].val );
		}
	}
	cout<<dp[x][y]<<endl;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		input();
		solve();
	}
	return 0;
}

發佈了30 篇原創文章 · 獲贊 92 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章