链接: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. javascript面向对象之闭包

    javascript面向对象之闭包 学习javascript一段时间了,自己对闭包作出如下总结,如有某点不妥,请君指出,不胜感激! 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量 ...

  2. oracle 修改dbid和dbname

    一般这玩意没人修改,除非特殊情况,比如克隆数据库等等 步骤: 1.备份数据库 2.启动数据到mount状态 3.nid命令修改 (如果只是修改dbid,那么不需要dbname参数,需要更改dbname ...

  3. HPUX平台经常使用命令列举

    原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlong ...

  4. MySQL初步研究数据库

    我用的是环境Win7.开始学习PHP和MySQL,而买了这<Head First PHP & MySQL>,从能Head First Labs官网获得HeadFirst系列书籍的相 ...

  5. bridge pattern

     10.5 桥接模式总结 桥接模式是设计Java虚拟机和实现JDBC等驱动程序的核心模式之一,应用较为广泛.在软件开发中如果一个类或一个系统有多个变化维度时,都可以尝试使用桥接模式对其进行设计.桥接模 ...

  6. 【Android进阶】Gson解析json字符串的简单应用

    在客户端与服务器之间进行数据传输,一般采用两种数据格式,一种是xml,一种是json.这两种数据交换形式各有千秋,比如使用json数据格式,数据量会比较小,传输速度快,放便解析,而采用xml数据格式, ...

  7. List Set Map用法和区别

    List,Set,Map是否继承自Collection接口? 答:List,Set是,Map不是.如图: Collection ├List │├LinkedList │├ArrayList │└Vec ...

  8. CallContext和多线程

    前一段时间正好要在某个网页程序上开一个多线程调用多个组件的尝试,这些组件是有其他团队开发的(如:印度/俄罗斯),所以修改它们的代码看起来是不太现实的,但是,令人恼火的是他们的代码中大量的用到了AppC ...

  9. 自动同步Android源代码的脚本(repo sync)

    #!/bin/bash echo "================start repo sync====================" repo sync -j5 ]; do ...

  10. 位图像素的颜色 携程编程大赛hdu

    位图像素的颜色 Time Limit: 2000/1000 MS (Java/Others)    MemoryLimit: 32768/32768 K (Java/Others) Total Sub ...