hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)
WHUgirls
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2068 Accepted Submission(s): 785
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.
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.
Constrains
0 < T <= 20
0 <= N <= 10; 0 < X, Y <= 1000
0 < xi <= X; 0 < yi <= Y; 0 <= ci <= 1000
1
2 4 4
2 2 2
3 3 9
9
这个题開始做的时候。一直分析。感觉应该是要用动态规划来做。其它做法应该会要超时,然后一直往动态规划那方面想。结果越想越复杂,感觉情况太多了。考虑不周全,后来看了一下别人的思路,直接能够转化为二维的全然背包问题。一大块完整的布就相当于一个背包,剪布料就相当于往里面放东西,由于剪矩形有长和宽。所以就是二维来做,每剪一块的价值就相当于背包的价值,最关键的是每一种能够剪多次,全然背包里面的一种物品能够放多次;
看了这一篇博客的分析:http://blog.csdn.net/lulipeng_cpp/article/details/7587465
题目的意思就是要我们能够剪的最大价值,所以设立 dp[i][j]:长为i宽为j的矩形布的最大价值;
由于剪成矩形有两种情况能够剪,(能够參看上面的博客),一种直接是依照长来剪,还能够依照宽来剪。剪了之后,一块矩形的布可能就不是一个矩形了,我们就把它分成三块来算,分成3个小矩形。我们要求的就是这三个小矩形的面积之和;设立 要剪去的矩形的长为x,宽为y。(图片直接是上面的博客里面的)
我们就有两种剪法:
第一种:
这里我们就能够得到方法一的状态方程式;w为剪去的小矩形的价值;
dp[i][j]=max(dp[i][j],max(dp[i-x][j]+dp[x][j-y],dp[i][j-y]+dp[i-x][y])+w);
另外一种:
dp[i][j]=max(dp[i][j],max(dp[i-y][j]+dp[y][j-x],dp[i][j-x]+dp[i-y][x])+w);
以下的ac的代码。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct bag
{
int x,y,value;
};
bag bag[10];
int dp[1001][1001];
int main()
{
int t,n,x,y,i,j,k;
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof(dp));
scanf("%d%d%d",&n,&x,&y);
for(i=0;i<n;i++)
scanf("%d%d%d",&bag[i].x,&bag[i].y,&bag[i].value);
for(i=0;i<=x;i++)
for(j=0;j<=y;j++)
for(k=0;k<n;k++)
{
if(i>=bag[k].x && j>=bag[k].y)//第一种剪法;
dp[i][j]=max(dp[i][j],max((dp[i-bag[k].x][j]+dp[bag[k].x][j-bag[k].y]),(dp[i][j-bag[k].y]+dp[i-bag[k].x][bag[k].y]))+bag[k].value);
if(i>=bag[k].y && j>=bag[k].x)//另外一种剪法;
dp[i][j]=max(dp[i][j],max((dp[i-bag[k].y][j]+dp[bag[k].y][j-bag[k].x]),(dp[i][j-bag[k].x]+dp[i-bag[k].y][bag[k].x]))+bag[k].value);
}
printf("%d\n",dp[x][y]);
}
return 0;
}
hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)的更多相关文章
- hdu 3123 GCC (2009 Asia Wuhan Regional Contest Online)
GCC Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- HDU 3126 Nova [2009 Asia Wuhan Regional Contest Online]
标题效果 有着n巫妖.m精灵.k木.他们都有自己的位置坐标表示.冷却时间,树有覆盖范围. 假设某个巫妖攻击精灵的路线(他俩之间的连线)经过树的覆盖范围,表示精灵被树挡住巫妖攻击不到.求巫妖杀死所有精灵 ...
- hdu 3123 2009 Asia Wuhan Regional Contest Online
以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次 n>=m 则n!==0 注意的一点,最后 看我的凝视 #include <cstdio> #includ ...
- hdu3231 (三重拓扑排序) 2009 Asia Wuhan Regional Contest Hosted by Wuhan University
这道题算是我拓扑排序入门的收棺题了,卡了我好几天,期间分别犯了超时,内存溢出,理解WA,细节WA,格式WA…… 题目的意思大概是在一个三维坐标系中,有一大堆矩形,这些矩形的每条棱都与坐标轴平行. 这些 ...
- HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)
Problem Description Peer-to-peer(P2P) computing technology has been widely used on the Internet to e ...
- HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang
感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...
- HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- zoj 3659 Conquer a New Region The 2012 ACM-ICPC Asia Changchun Regional Contest
Conquer a New Region Time Limit: 5 Seconds Memory Limit: 32768 KB The wheel of the history roll ...
- 2018 ACM-ICPC Asia Beijing Regional Contest (部分题解)
摘要 本文主要给出了2018 ACM-ICPC Asia Beijing Regional Contest的部分题解,意即熟悉区域赛题型,保持比赛感觉. Jin Yong’s Wukong Ranki ...
随机推荐
- 循环和递归的区别(以前以为递归就是for循环!错的!)
这里直接上代码!!!! //代码1:(for循环实现的代码) void main() { ; ; i<;i++) { n++; } printf("%d",n); } //代 ...
- CREATE GROUP - 定义一个新的用户组
SYNOPSIS CREATE GROUP name [ [ WITH ] option [ ... ] ] where option can be: SYSID gid | USER usernam ...
- C#通过post发送接收数据流
发送数据流方法 /// <summary> /// /// </summary> /// <param name="url">目标url< ...
- CAD使用GetAllAppName读所有名称(com接口)
主要用到函数说明: MxDrawEntity::GetAllAppName 得到所有扩展数据名称,详细说明如下: 参数 说明 [out, retval] IMxDrawResbuf** ppRet 返 ...
- Oracle数据库存储过程练习20181212
先创建一个测试的数据表 --测试表 CREATE TABLE TEST20181207 ( ID INTEGER PRIMARY KEY, FUND NUMBER,--上日资金 BALANCE NUM ...
- DHCP和PXE
继续学习,Let's go!DHCP和PXE都是什么呢?如果非科班出身,可能一脸懵逼,好多东西需要去学习了,真的,继续学吧,付出不一定会有回报,不付出肯定就是等死了,呵呵! 一.DHCP 真正需要手动 ...
- gdb 基础
版权:https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html 1. gdb 调试利器 GDB是一个由GNU开源组织发布的.UN ...
- IO之DataStream数据流举例
import java.io.*; public class TestDataStream { public static void main(String[] args) { ByteArrayOu ...
- 安装配置elasticsearch、安装elasticsearch-analysis-ik插件、mysql导入数据到elasticsearch、安装yii2-elasticsearch及使用
一.安装elasticsearch 获取elasticsearch的rpm:wget https://download.elastic.co/elasticsearch/release/org/ela ...
- mysql、MariaDB的简单操作
mysql的简单操作 一.查看数据库 SHOW DATABASES; 例如: MariaDB [(none)]> show databases; +--------------------+ | ...