HDU 3127 WHUgirls (线性dp 完全背包)
2015-04-03 20:56
363 查看
WHUgirls
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2234 Accepted Submission(s): 844
Problem DescriptionThere 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
Source
2009 Asia Wuhan Regional Contest Online
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3127
题目大意:给一个矩形,将矩形切成给定任意个数的小矩形,当然每一个小矩形都有对应的权值,求最大权值
题目分析:dp[i][j]表示从(0,0)到(i,j)对应的矩形可以切出小矩形的最大权值和,然后就是背包搞一下,分横竖两种切法
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int const MAX = 1005; struct rec { int x, y; int val; }r[15]; int dp[MAX][MAX]; int main() { int T, n, X, Y; scanf("%d", &T); while(T--) { scanf("%d %d %d", &n, &X, &Y); memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i++) scanf("%d %d %d", &r[i].x, &r[i].y, &r[i].val); for(int i = 1; i <= X; i++) { for(int j = 1; j <= Y; j++) { for(int k = 0; k < n; k++) { for(int type = 0; type < 2; type++)//枚举2种矩形,横放,竖放 { if(type % 2) swap(r[k].x, r[k].y); if(r[k].x <= i && r[k].y <= j) { dp[i][j] = max(dp[i][j], dp[i - r[k].x][j] + dp[r[k].x][j - r[k].y] + r[k].val); //横切 dp[i][j] = max(dp[i][j], dp[i][j - r[k].y] + dp[i - r[k].x][r[k].y] + r[k].val); //竖切 } } } } } printf("%d\n", dp[X][Y]); } }
相关文章推荐
- 【DP】HDU 3127 WHUgirls 完全背包
- 【DP】HDU 3127 WHUgirls 完全背包
- HDU 3127 WHUgirls(DP 完全背包)
- HDU 3127 WHUgirls(完全背包)
- HDU 3127 WHUgirls(完全背包)
- hdu 3127 WHUgirls 二维完全背包
- HDU 3127 WHUgirls dp背包问题
- HDU 3127 WHUgirls【二维完全背包】
- HDU-3127-WHUgirls(完全背包)
- HDU 3127 WHUgirls(完全背包)
- HDU 3127 WHUgirls dp背包问题
- hdu 3127 WHUgirls(完全背包)
- 【HDU 3127】WHUgirls(二维完全背包)
- HDU 3127 WHUgirls(二维背包)
- HDU OJ 3127 WHUgirls【DP之背包】
- HDU_3127 WHUgirls(DP)
- HDU OJ 3127 WHUgirls【DP之背包】
- hdu 3127 WHU girls 2009武汉网络赛 dp
- HDU 3127 WHUgirls(二维背包)
- hdu 3127 WHUgirls【dp】好题~