zoj1013 Great Equipment
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1013
大三了,准备刷一下动态规划,保持思维的灵活性,这一次从zoj刷起,一道道刷,今天是9月29日,这是第一道。
这一道题目很长,题意:有n辆车,有三种材料,每种材料有独特的两种属性w,s,和一种防御值,按照题意,取几个组合可以形成一个comb,获得组合防御值(原先的不算了),每辆车也有w,s限制,求最大的防御值(所有材料每个小于500)
这道题有两个限制条件w,s,很容易想到二维背包,但是有三种材料,如果f[i][w][s]取得是防御值的话,那么组合,材料选取,情况将很复杂,然而组合的和每辆车的情况无关,只和总情况有关,所以定义f[i][j][k]为前i辆车取了j个头盔,k个铠甲时最大可取的靴子数量,先把所有可能情况dp统计出来,因为数据范围比较小,材料小于500,相当于带减枝的搜索。
可以使用滚动数组节省空间,转移方程f[i][j+k1][k+k2]=max(f[1-i][j][k]+cal(i,k1,k2)),转移时因为最大可取的靴子数为0也是合法的一种情况,所以我们需要把不合法(或者初始不确定情况)定义为-1;
这道题的关键在于状态的定义,滚动数组也熟悉了使用了一下。
130ms
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
int w1,s1,c1,w2,s2,c2,w3,s3,c3,g1,g2,g3,all,n;
struct big
{
int w,s;
}hh[];
int f[][][]; void read()
{
cin>>w1>>s1>>c1;
cin>>w2>>s2>>c2;
cin>>w3>>s3>>c3;
cin>>g1>>g2>>g3>>all;
for(int i=;i<n;i++)
{
cin>>hh[i].w>>hh[i].s;
}
} void solve()
{
memset(f,,sizeof(f));
int ans1=,ans2=,ans=;
for(int k=;k<n;k++)
{
int ansx=ans1;
int ansy=ans2;
memset(f[ans],-,sizeof(f[ans]));
for(int i=;i<=ans1;i++)
{
for(int j=;j<=ans2;j++)
{
if(f[-ans][i][j]!=-)
{
for(int k1=;k1*w1<=hh[k].w&&k1*s1<=hh[k].s;k1++)
{
int t1=hh[k].w-k1*w1;
int t2=hh[k].s-k1*s1;
for(int k2=;k2*w2<=t1&&k2*s2<=t2;k2++)
{
int tt=min((t1-k2*w2)/w3,(t2-k2*s2)/s3);
f[ans][i+k1][j+k2]=max(f[ans][i+k1][j+k2],f[-ans][i][j]+tt);
ansx=max(ansx,i+k1);
ansy=max(ansy,j+k2);
}
}
} }
}
ans1=ansx;
ans2=ansy;
ans=-ans;
}
ans=-ans;
int res=;
for(int i=;i<=ans1;i++)
for(int j=;j<=ans2;j++)
{
int xx=f[ans][i][j];
if(xx==-)
continue;
if(g1*c1+g2*c2+g3*c3>=all)
{
res=max(res,i*c1+j*c2+xx*c3);
}
else
{
int yy=min(i/g1,min(j/g2,xx/g3));
res=max(res,yy*all+(i-yy*g1)*c1+(j-yy*g2)*c2+(xx-yy*g3)*c3);
}
}
printf("%d\n",res);
}
int main()
{
//freopen("input.txt","r",stdin);
int cas=;
while(cin>>n&&n)
{
if(cas>)
puts("");
printf("Case %d: ",cas++);
read();
solve();
}
}
zoj1013 Great Equipment的更多相关文章
- Equipment Box[HDU1110]
Equipment Box Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU ACM 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 杭电 3177 Crixalis's Equipment
http://acm.hdu.edu.cn/showproblem.php? pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/ ...
- Hdu 3177 Crixalis's Equipment
Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- /Home/Tpl/Equipment/rangeIndex.html 里调用魔板
<pre name="code" class="html">demo:/var/www/DEVOPS# vim ./Home/Tpl/Equipme ...
- HDU 3177 Crixalis's Equipment(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...
- Equipment UVA - 1508(子集补集)
The Korea Defense and Science Institute, shortly KDSI, has been putting constant effort into newequi ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
随机推荐
- HttpContext详解【转】
HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息. 在处理请求执行链的各个阶段中,会有一个对象在各个对象之间进行传递,也即会保存请求的上下文信息,这个对象就是Htt ...
- Android UI目录
Android UI目录 序:最近一直想进阶android应用开发,虽然对一些相关的android知识都大体熟悉,但是自己的android知识体系,经不起推敲.经不起高手的垂问.经过几个月的努力学习, ...
- UVA - 10574 Counting Rectangles
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...
- ORACLE表空间管理方式segment和extent
A permanent tablespace contains persistent schema objects. Objects in permanent tablespaces are stor ...
- WCF学习心得
之前很经常听说WCF,不过没有怎么接触过,直到最近才真正使用到WCF,虽然也只是皮毛而已,在此也做个记录总结吧. 下图是我使用WCF的练手项目,由于是使用VS2010直接创建的WCF服务应用程序,VS ...
- table中超长字符串省略号表示两种方法
写在前面: 1.第一种从网上找到的解决方式添加table-layout:fixed 2.第二种添加div 3.字符串过长产生省略号的css语句为如下三种合用:overflow:hidden ...
- SQL性能优化的思路建议
如何在 Oracle数据库里写出高质量的SQL语句,如何在Oracle数据库里对有性能问题的SQL做诊断和调整,这是DBA们在ORACLE数据库实践中不可避免的难题.下面就让我们来分析一下拿到一条问题 ...
- C++学习之重载运算符1
C++除可重载函数之后,还允许定义已有的运算符,这样通过运算符重载可像处理数据使用它们. 先来个代码 #include<iostream> using namespace std; cla ...
- sublime前端编辑器入门与个人使用经验分享
Sublime Text(以下简称sublime)是一款很好用的代码编辑器,小巧且很灵敏,几乎可以编写大部分主流的计算机语言代码,更是堪称前端代码编辑神器. 你百度一下会发现许多sublime的安装和 ...
- Hibernate的Criteria用法
在hibernate的Session里面使用createCriteria可以创建一个Criteria实例帮助我们进行条件查询,不用自己串hql语句,很方便. 用法很简单,首先传Class实例创建Cri ...