HDU-3127 WHUgirls
来源:互联网 发布:mac u盘不显示 编辑:程序博客网 时间:2024/05/19 12:26
WHUgirls
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2557 Accepted Submission(s): 952
Total Submission(s): 2557 Accepted Submission(s): 952
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
分析:这道题的主要意思是有一块布,有一台机器可以对其进行切割,但只能一刀切到底。有n种不同形状规格的布,价值也各有不同,要求尽可能使得剪切过的布条加起来的总价值最大,当然,并没有说明一定要把布料用完。这很明显是背包问题,而且是完全背包,情况可以这么判断:这块布可以横放,也可以纵放。也可以横切,也可以纵切,这样就有四种情况,如下图所示:
图一和图二是横放的两种情况,图三和图四是纵放的两种情况。
1.f[i][j-y[k]]+f[i-x[k]][y[k]]+c[i];
2.f[x[k]][j-y[k]]+f[i-x[k]][j]+c[i];
3.f[i-y[k]][j]+f[j-x[k]][y[k]]+c[i];
4.f[x[k]][i-y[k]]+f[i][j-y[k]]+c[i];
附上AC源代码:
#include<stdio.h>#include<string.h>int T,X,Y;int f[1005][1005];int max(int a,int b){return a>b?a:b;}int main(){int i,j,k,N;int x[15],y[15],c[15];scanf("%d",&T); while(T--){scanf("%d %d %d",&N,&X,&Y);for(i=0;i<N;i++)scanf("%d %d %d",&x[i],&y[i],&c[i]);for(i=0;i<=X;i++)for(j=0;j<=Y;j++)for(k=0;k<N;k++){if(i>=x[k]&&j>=y[k])f[i][j]=max(f[i][j],max(f[i-x[k]][j]+f[x[k]][j-y[k]]+c[k],f[i][j-y[k]]+f[i-x[k]][y[k]]+c[k]));if(i>=y[k]&&j>=x[k])f[i][j]=max(f[i][j],max(f[i-y[k]][j]+f[y[k]][j-x[k]]+c[k],f[i][j-x[k]]+f[i-y[k]][x[k]]+c[k])); }printf("%d\n",f[X][Y]);}return 0;}
1 0
- hdu 3127 WHUgirls
- hdu 3127 WHUgirls
- HDU 3127 WHUgirls
- HDU 3127 WHUgirls
- hdu 3127 WHUgirls
- 【HDU】 3127 WHUgirls
- HDU-3127 WHUgirls
- HDU 3127 WHUgirls 背包问题
- HDU 3127 WHUgirls (完全背包)
- HDU 3127 WHUgirls(完全背包)
- hdu-3127-WHUgirls解题报告
- HDU 3127 WHUgirls(完全背包)
- HDU OJ 3127 WHUgirls【DP之背包】
- hdu 3127 WHUgirls 二维完全背包
- HDU 3127 WHUgirls dp背包问题
- HDU OJ 3127 WHUgirls【DP之背包】
- hdu——3127——WHUgirls
- 【DP】HDU 3127 WHUgirls 完全背包
- Android Hook(1) Dexposed原理
- Android Hook(2) Java2java
- 从零学习Swift<1>
- Unit testing code that uses HttpContext.Current.Session
- spring 中文乱码解决办法
- HDU-3127 WHUgirls
- 【感悟】战略上藐视敌人,战术上重视敌人
- MySQL加密函数
- Android应用资源文件格式解析与保护对抗研究
- 软件问题定位的方法(二)
- 每天读一点儿APM(PIX)代码之三:飞行控制
- css div垂直居中
- 扩展欧几里德
- 从零学习Swift<2>