题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=13

很经典的一个DP的题目

定义dp[i][num1][num2]表示前i个车装num1个装备1和num2个装备2之后最多能装的装备3的个数

那么dp[i][p+x][q+y]=max(dp[i][p+x][q+y],dp[i-1][p][q]+num(x,y));

其中num(x,y)表示第i辆车装x个装备1和y个装备2后还能最多装的装备3的个数

x,y的范围即为第辆车的可以装的装备1和装备2的最大个数

可以看出dp[i]只与dp[i-1]有关,要用滚动数组,否则会超内存

代码:

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#define maxn 550
#define maxn_1 110
using namespace std;
int dp[][maxn][maxn];
int w[maxn_1];
int s[maxn_1];
int w1,s1,d1;
int w2,s2,d2;
int w3,s3,d3;
int c1,c2,c3,d4;
int prev,now;
int put(int num,int p,int q)
{
int nw=(w[num]-p*w1-q*w2)/w3;
int ns=(s[num]-p*s1-q*s2)/s3; return min(nw,ns);
}
int main()
{
int n;
int icase=;
while(scanf("%d",&n) != EOF&& n)
{
scanf("%d%d%d",&w1,&s1,&d1);
scanf("%d%d%d",&w2,&s2,&d2);
scanf("%d%d%d",&w3,&s3,&d3);
scanf("%d%d%d",&c1,&c2,&c3);
scanf("%d",&d4); for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&s[i]);
memset(dp[],,sizeof(dp[])); int max_1=;
int max_2=;
prev=,now=;
for(int i=;i<=n;i++)
{
memset(dp[now],-,sizeof(dp[now]));
int num1=min(w[i]/w1,s[i]/s1);
int tmp;
for(int p=;p<=num1;p++)
{
int num2=min((w[i]-p*w1)/w2,(s[i]-p*s1)/s2);
if(p==) tmp=num2; for(int q=;q<=num2;q++)
{
int nn=put(i,p,q);
for(int k1=;k1<=max_1;k1++)
for(int k2=;k2<=max_2;k2++)
{
if(dp[prev][k1][k2]!=-)
dp[now][k1+p][k2+q]=max(dp[now][k1+p][k2+q],dp[prev][k1][k2]+nn);
}
}
} max_1+=num1;
max_2+=tmp;
swap(now,prev); }
int ans=;
for(int i=;i<=max_1;i++)
for(int j=;j<=max_2;j++)
{
if(dp[prev][i][j]!=-)
{
int num_4=min(min(i/c1,j/c2),dp[prev][i][j]/c3);
ans=max(max(ans,i*d1+j*d2+dp[prev][i][j]*d3),(i-num_4*c1)*d1+(j-num_4*c2)*d2+(dp[prev][i][j]-num_4*c3)*d3 +num_4*d4);
}
}
if(icase++) cout<<endl;
cout<<"Case "<<icase<<": "<<ans<<endl;
}
return ;
}

zoj 1013 Great Equipment DP的更多相关文章

  1. ZOJ 1013 Great Equipment(DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=13 题目大意:说的是有三种不同的装备,分别是头盔,盔甲,战靴需要运输, ...

  2. ZOJ Problem Set - 3822Domination(DP)

    ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...

  3. zoj 3537 Cake 区间DP (好题)

    题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...

  4. ZOJ 3769-Diablo III(DP)

    描述 Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new e ...

  5. ZOJ 3623 Battle Ships DP

    B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  6. zoj 2860 四边形优化dp

    Breaking Strings Time Limit: 2 Seconds        Memory Limit: 65536 KB A certain string-processing lan ...

  7. Problem Arrangement ZOJ - 3777(状压dp + 期望)

    ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...

  8. ZOJ 3306 状压dp

    转自:http://blog.csdn.net/a497406594/article/details/38442893 Kill the Monsters Time Limit: 7 Seconds ...

  9. [ACM] ZOJ 3725 Painting Storages (DP计数+组合)

    Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with ...

随机推荐

  1. NGINX下配置CACHE-CONTROL

    HTTP协议的Cache -Control指定请求和响应遵循的缓存机制.在请求消息或响应消息中设置 Cache-Control并不会影响另一个消息处理过程中的缓存处理过程.请求时的缓存指令包括no-c ...

  2. python中input()与raw_input()的区别到底是啥?-----marsggbo原创作品为你解答

    首先先给出总结:input () = int(raw_input()) 有图有真相!!! 先看看input的例子: 可见用input键入得到int类型的数据,那如果输入一些非int类型的会怎么样呢? ...

  3. git clone操作到开发机的错误记录

    在开发机上,执行操作 $ git clone https://github.com/xxx/rank.git 返回错误: error: The requested URL returned error ...

  4. 27. Remove Element - 移除元素-Easy

    Description: Given an array and a value, remove all instances of that value in place and return the ...

  5. ECMAScript6-解构

    ▓▓▓▓▓▓ 大致介绍 解构:就是将声明的一组变量和与相同结构的数组或者对象的元素数值一一对应,并将变量相对应元素进行赋值 ▓▓▓▓▓▓ 数组解构 例子: let [a,b,c] = [1,2,3]; ...

  6. servlet与jsp的区别(转)

    一.基本概念 1.1 Servlet Servlet是一种服务器端的Java应用程序,具有独立于平台和协议的特性,可以生成动态的Web页面.它担当客户请求(Web浏览器或其他HTTP客户程序)与服务器 ...

  7. 老李回答:JAVA程序的性能测试方法

    Java 1.5以上都在虚拟机里内建了程序性能跟踪的功能,并提供了Java Profiling API,简称JPA,你可以搜索'java profiling'.Java也提供了简单的性能性能跟踪工具J ...

  8. 手机自动化测试:Appium源码分析之跟踪代码分析八

    手机自动化测试:Appium源码分析之跟踪代码分析八   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家 ...

  9. 6.Java集合总结系列:常见集合类的使用(List/Set/Map)

    MARK 总结: Set.List 和 Map 可以看做集合的三大类. List集合是有序集合,集合中的元素可以重复,访问集合中的元素可以根据元素的索引来访问. Set集合是无序集合,集合中的元素不可 ...

  10. 【Android】沉浸式状态栏实现

    在Android4.4(API 19)及以后的版本中都增加了对沉浸式状态栏的支持,实现起来也很简单,将application的主题稍作修改即可: <style name="AppThe ...