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 ...
随机推荐
- PC端浏览器定位
第一: PC端浏览器定位(纯前端)浏览器定位 :这里用了两种 ,一种是Html5自带的方法 另一种是引用了百度api ,百度api 的使用有三种:1 浏览器定位2 ip定位3 SDK辅助定位引用百度 ...
- docker 容器挂载主机目录,访问出现 cannot open directory /mnt/home/webroot/: Permission denied 的解决办法
问题原因及解决办法 原因是CentOS7中的安全模块selinux把权限禁掉了,至少有以下三种方式解决挂载的目录没有权限的问题: 1.在运行容器的时候,给容器加特权,及加上 --privileged= ...
- CSS 实现毛玻璃效果
Part.1 HTML结构 <!-- 最外层盒子 --> <div class="box"> <!-- 添加毛玻璃效果盒子 --> <di ...
- java引用数据类型在方法中的值传递
package org.jimmy.autosearch20180821.test; public class TestStringArr { public static void main(Stri ...
- HTML 之 DOM文件对象模型
文件对象模型 (DOM: Document Object Model) DOM 是 W3C定义的一种访问文档的标准. "The W3C Document Object Model (DOM) ...
- KBE_那些事
批处理文件不要放在工具栏执行,这里有坑:工具栏运行批处理文件,当前路径(%cd%)不是批处理文件所在路径 日志的输出(DEBUG_MSG 和 INFO_MSG)都被输出在({资产库}/logs/*.l ...
- [Python3网络爬虫开发实战] 3.1.2-处理异常
前一节我们了解了请求的发送过程,但是在网络不好的情况下,如果出现了异常,该怎么办呢?这时如果不处理这些异常,程序很可能因报错而终止运行,所以异常处理还是十分有必要的. urllib的error模块定义 ...
- ubuntu 安装 navicat
下载navicat解压到opt目录 创建桌面快捷方式sudo vim /usr/share/applications/navicat.desktop [Desktop Entry] Encoding= ...
- 第十一节:pandas统计函数
1.pct_change()计算增长比例 2.cov()协方差 3.corr()相关系数 4.rank()数据排名 5.numpy聚合函数
- hadoop_exporter+prometheus
1.准备工作 安装go.glibe(需要连google服务器,咋连的,我就不写了,因为尝试了各种办法,都失败了,很伤心) 2.下载hadoop_exporter cd /usr/local/prom/ ...