HDOJ 题目3127 WHUgirls(完全背包)
来源:互联网 发布:汇龙营销软件 编辑:程序博客网 时间:2024/05/16 11:29
WHUgirls
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2146 Accepted Submission(s): 816
Problem Description
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.
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
Constrains
0 < T <= 20
0 <= N <= 10; 0 < X, Y <= 1000
0 < xi <= X; 0 < yi <= Y; 0 <= ci <= 1000
Sample Input
12 4 42 2 23 3 9
Sample Output
9
Source
2009 Asia Wuhan Regional Contest Online
Recommend
lcy | We have carefully selected several similar problems for you: 3123 3126 3124 3125 3120
ac代码
截取一个矩形剩下的不一定是矩形
ac代码
#include<stdio.h>#include<string.h>#include<stdlib.h>#define max(a,b) (a>b?a:b)int dp[1010][1010];struct s{int x,y,w;}b[1010];int cmp(const void *a,const void *b){return (*(struct s *)b).w-(*(struct s *)a).w;}int main(){int t;scanf("%d",&t);while(t--){int n,sx,sy,i,j,k;scanf("%d%d%d",&n,&sx,&sy);for(i=0;i<n;i++){scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].w);}qsort(b,n,sizeof(b[0]),cmp);memset(dp,0,sizeof(dp));for(i=0;i<=sx;i++){for(j=0;j<=sy;j++){for(k=0;k<n;k++){if(i>=b[k].x&&j>=b[k].y)dp[i][j]=max(dp[i][j],max(dp[i-b[k].x][j]+dp[b[k].x][j-b[k].y]+b[k].w,dp[i][j-b[k].y]+dp[i-b[k].x][b[k].y]+b[k].w));if(i>=b[k].y&&j>=b[k].x)dp[i][j]=max(dp[i][j],max(dp[i-b[k].y][j]+dp[b[k].y][j-b[k].x]+b[k].w,dp[i][j-b[k].x]+dp[i-b[k].y][b[k].x]+b[k].w));}}}printf("%d\n",dp[sx][sy]);}}
0 0
- HDOJ 题目3127 WHUgirls(完全背包)
- hdu 3127 WHUgirls(完全背包)
- 【HDU 3127】WHUgirls(二维完全背包)
- HDU-3127-WHUgirls(完全背包)
- HDU 3127 WHUgirls (完全背包)
- HDU 3127 WHUgirls(完全背包)
- HDU 3127 WHUgirls(完全背包)
- hdu 3127 WHUgirls 二维完全背包
- 【DP】HDU 3127 WHUgirls 完全背包
- HDU 3127 WHUgirls (线性dp 完全背包)
- HDU3127:WHUgirls(二维完全背包)
- HDU3127:WHUgirls(完全背包)
- HDOJ 题目1963 Investment(完全背包)
- hdu 3127 WHUgirls(二维背包)
- HDU 3127 WHUgirls(二维背包)
- HDU 3127 WHUgirls(二维背包)
- HDOJ 题目1114Piggy-Bank(完全背包,动态规划)
- HDOJ 题目2159FATE(二维完全背包)
- AES加密解密
- 本学期schedule
- open 函数
- java的System.getProperty()方法可以获取的值
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- HDOJ 题目3127 WHUgirls(完全背包)
- meta标签中的http-equiv属性使用介绍
- stock mina框架,自动重连
- “高,富,快的互联网”
- android基本 UI(四)—时间选择器TimePicker和日期选择器 DatePicker
- 深圳健丽国际医学美容集团的兼职编辑招聘是骗人的!
- mp4格式学习(一)
- 安卓客户端,服务端
- VPN网站