链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623

题意:给出N种可以建造的船和对方的塔生命值L,每种船给出建造时间t[i]和每秒输出dps[i],船坞在同一时间仅仅能建造一支船(类似红警),问多少时间以后可以灭掉塔。

思路:dp[i]代表的是在前i秒内能造成的伤害量,把时间反过来考虑,对于每支船的建造,在前i秒内所占用的建造时间是第i-t[i]+1~i秒,状态转移方程是dp[i+t[j]]=max(dp[i+t[j]],dp[i]+dps[j]*i),因为建设船的时间是第i~t[i]+1~i秒,所以在状态转移时不会出现建设时间的重叠情况。

P.S.比赛的时候不机智了,题意里的each time被我理解成了每秒能够选择造一艘新的船。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int t[35],dps[35];
int dp[355];
int main()
{
int N,L;
while(~scanf("%d%d",&N,&L))
{
memset(dp,0,sizeof(dp));
for(int i=0;i<N;i++)
scanf("%d%d",&t[i],&dps[i]);
for(int i=0;i<=L+20;i++)
for(int j=0;j<N;j++)
dp[i+t[j]]=max(dp[i+t[j]],dp[i]+dps[j]*i);
for(int i=0;i<=L+20;i++)
if(dp[i]>=L)
{
printf("%d\n",i);
break;
}
}
return 0;
}

ZOJ 3623 Battle Ships 简单DP的更多相关文章

  1. ZOJ 3623 Battle Ships DP

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

  2. [ZOJ 3623] Battle Ships

    Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is s ...

  3. ZOJ 3349 Special Subsequence 简单DP + 线段树

    同 HDU 2836 只不过改成了求最长子串. DP+线段树单点修改+区间查最值. #include <cstdio> #include <cstring> #include ...

  4. Codeforces 567D One-Dimensional Battle Ships

    传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...

  5. ZOJ3623:Battle Ships(全然背包)

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  6. Battle Ships(复习泛化物品**)

    传送门Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which i ...

  7. zoj3623 Battle Ships

    Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...

  8. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞

    D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

随机推荐

  1. android 图片浏览器 demo

    先上效果图,本demo 会逐步完好 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTU2NTczMDE2NjEz/font/5a6L5L2T/fontsi ...

  2. android中listview分页载入数据

    前段时间做的新浪微博项目一直想实现listview分页载入数据,今天最终实现了,哈哈!感觉挺好的,今天又写了个demo给大家分享下. 首先说下listview的优化方案,这也是面试中常考的题目.优化方 ...

  3. ZooKeeperEclipse 小工具

    插件地址:ZooKeeperEclipse  http://www.massedynamic.org/eclipse/updates/ 安装ZooKeeperEclipse插件过程例如以下: Step ...

  4. python关于for循环的几个函数

    1.enumerate:返回2个值,1是当前的for循环的第几轮,2是循环得到的数值 enumerate works by supplying a corresponding index to eac ...

  5. 【数据结构&amp;&amp;等差数列】KMP简介和算法的实现(c++ &amp;&amp; java)

    KMP算法假定了解案件的原则,其实很easy. KMP算法简述 关于根据自己的理解在这里. KMP该算法由三个发明人的名称(Knuth.Morris.Pratt)的首字母组成,又称字符串查找算法. 个 ...

  6. chain pattern

    16.4 纯与不纯的职责链模式 职责链模式可分为纯的职责链模式和不纯的职责链模式两种:        (1) 纯的职责链模式 一个纯的职责链模式要求一个具体处理者对象只能在两个行为中选择一个:要么承担 ...

  7. 如何设置一个activity透明

    1.在AndroidManifest.xml文件中设置: android:theme="@android:style/Theme.Translucent 此代码固定为全背景透明. 2.在Ac ...

  8. 在mac os下编译android -相关文章

    1. Mac OS X下编译Android源码 http://blog.csdn.net/bulreed/article/details/22783467 2.MAC OS 编译 Android源代码 ...

  9. 苹果Swift编程语言新手教程【中文版】

    文件夹 1 简单介绍 2 Swift入门 3 简单值 4 控制流 5 函数与闭包 6 对象与类 7 枚举与结构 1 简单介绍 Swift是供iOS和OS X应用编程的新编程语言,基于C和Objecti ...

  10. MySQL 最经常使用的一千行

    /* 启动MySQL */ net start mysql /* 连接和断开server */ mysql -h 住址 -P port -u username -p password /* 跳过许可认 ...