ZOJ 3623 Battle Ships 简单DP
链接: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的更多相关文章
- ZOJ 3623 Battle Ships DP
B - Battle Ships Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
- ZOJ 3349 Special Subsequence 简单DP + 线段树
同 HDU 2836 只不过改成了求最长子串. DP+线段树单点修改+区间查最值. #include <cstdio> #include <cstring> #include ...
- Codeforces 567D One-Dimensional Battle Ships
传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- Battle Ships(复习泛化物品**)
传送门Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which i ...
- zoj3623 Battle Ships
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 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 ...
随机推荐
- 【足迹C++primer】52、,转换和继承虚函数
转换和继承,虚函数 Understanding conversions between base and derived classes is essential to understanding h ...
- hdu4336压缩率大方的状态DP
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception 依赖注入容器Uni ...
- JS学习笔记-OO疑问之对象创建
问一.引入工厂,解决反复代码 前面已经提到,JS中创建对象的方法,不难发现,主要的创建方法中,创建一个对象还算简单,假设创建多个类似的对象的话就会产生大量反复的代码. 解决:工厂模式方法(加入一个专门 ...
- android-adb通用
- ios ios7 取消控制拉升
//推断是否ios7 取消控制拉升 if ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0) { self.edgesFo ...
- linux下"="号与"=="号
<鸟哥的linux私房菜>基础学习篇P382中说,在bash中"="与"=="是同样的,都代表推断是否相等,仅仅只是因为其它语言一般写法使用&quo ...
- HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法
联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...
- mysql监视器MONyog的使用
MONyog是个商业收费软件,可是能够找一下破解版.我用的是4.72破解版 1. 图1.1 在server设置中,如图1.1. 在Sniffer Settings里Enable sniff ...
- c# 通过配置自动附加数据库
using System; using System.Collections.Generic; using System.Windows.Forms; using System.Data.SqlCli ...