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& ...
随机推荐
- Anton and Lines(思维)
Anton and Lines time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 第一次用shell脚本来自动运行带参程序
将目录下的part-开头的文件带入程序处理 #!bin/sh FILES=/data5/follow_relation_list_part_00000/part-* file="" ...
- VB读写Excel
近期用excel和VB比較多,就简单的学习了一下VB中对Excel的处理.今天就介绍一些吧. 在VB中要想调用Excel,须要打开VB编程环境“project”菜单中的“引用”项目 ...
- 解决初学者学不懂android,不理解android的设计
最近在忙着搞一个小项目,所以没有来得及写一些原创性的东西,好容易今天中秋节,就趁现在写一些吧,今天仍然看了些老马的视频,尽管这些东西以前都用过,但是感觉仍然学到了不少东西,说给大家听希望大家也要不要不 ...
- Spark里面的任务调度:离SparkContext开始
SparkContext这是发达国家Spark入学申请,它负责的相互作用和整个集群,它涉及到创建RDD.accumulators and broadcast variables.理解力Spark架构, ...
- C#整理7——函数
数据类型--变量常量--运算符表达式--语句(顺序,分支,循环)--数组--函数 函数 1.定义:能够独立完成某个功能的模块.2.好处:1.结构更清析(编写.维护方便 ).2.代码重用.3.分工开发. ...
- Android Studio 没有assets目录的问题
Where to place the assets folder in Android Studio If you are having problems with asset files not ...
- In Depth : Android Boot Sequence / Process
In Depth : Android Boot Sequence / Process What happened when I press power on button in my Android ...
- Type Correlation
Types of correlation: Logical correlation: Using pre-defined and customized correlation rules. Inven ...
- node.js NPM 使用
n=NPM是一个Node包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准.有了NPM,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包.npms安装: 下载npm源 ...