ZOJ 3623 Battle Ships DP
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes ti seconds to produce the i-th battle ship and this battle ship can make the tower loss li longevity every second when it has been produced. If the longevity of the tower lower than or equal to 0, the player wins. Notice that at each time, the factory can choose only one kind of battle ships to produce or do nothing. And producing more than one battle ships of the same kind is acceptable.
Your job is to find out the minimum time the player should spend to win the game.
Input
There are multiple test cases.
The first line of each case contains two integers N(1 ≤ N ≤ 30) and L(1 ≤ L ≤ 330), N is the number of the kinds of Battle Ships, L is the longevity of the Defense Tower. Then the following N lines, each line contains two integers t i(1 ≤ t i ≤ 20) and li(1 ≤ li ≤ 330) indicating the produce time and the lethality of the i-th kind Battle Ships.
Output
Output one line for each test case. An integer indicating the minimum time the player should spend to win the game.
Sample Input
1 1
1 1
2 10
1 1
2 5
3 100
1 10
3 20
10 100
Sample Output
2
4
5
//dp[i]代表时间为i时最多可以打掉的血
//然后找到第一个dp[i]>=L,那么就是最短的时间
//采用的是用当前状态去更新后面状态
//对于,j+T[i]时间段内,
//dp[j]更新dp[j+T[i]],表示一开始的T[i]秒是在建武器i
//在j的时间段内武器i一直都在工作,然后J时间段内套用j+T[i]时间段内的含义.
//所以该动规方法是可行的
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int N,L;
int T[],l[];
int dp[];
int main()
{
int i,j;
while(scanf("%d%d",&N,&L)!=EOF)
{
for(i=;i<=N;i++)
scanf("%d%d",&T[i],&l[i]);
memset(dp,,sizeof(dp));
for(j=;j<=L;j++)
for(i=;i<=N;i++)
dp[j+T[i]]=max(dp[j]+l[i]*j,dp[j+T[i]]);
for(i=;i<=;i++)
if(dp[i]>=L)
break;
printf("%d\n",i);
}
return ;
}
ZOJ 3623 Battle Ships DP的更多相关文章
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
- ZOJ 3623 Battle Ships 简单DP
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 题意:给出N种可以建造的船和对方的塔生命值L,每种船给出建造时 ...
- 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 ...
- Codeforces 567D One-Dimensional Battle Ships
传送门 D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes ...
- 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 ...
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
随机推荐
- asp.net操作word 配置在IIS上出现的问题
异常: 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问. (异常来自 ...
- Python基础二(输入与输出)
通常,一个程序都会有输入/输出,这样可以与用户进行交互.用户输入一些信息,你会对他输入的内容进行一些适当的操作,然后再输出给用户想要的结果.Python的输入/输出,我们可以用input进行输入,pr ...
- Bugfree3.0.4 Linux环境安装指南
一. 安装apache服务器 1. 检查apache服务器是否安装 service httpd status 2. 如提示未被识别的服务,则表明组件未安装,需手动安装 yum install http ...
- 使用html+css+js实现3D相册
使用html+css+js实现3D相册,快来上传的照片吧 效果图: 代码如下,复制即可用: <!DOCTYPE html> <html lang="en"> ...
- mysql慢sql报警系统
前言:最近有同事反应有的接口响应时间时快时慢,经过排查有的数据层响应时间过长,为了加快定位定位慢sql的准确性,决定简单地搭建一个慢sql报警系统 具体流程如下架构图 第一步:记录日志 每个业务系统都 ...
- java -D 参数功能解析
我们都知道在启动tomcat或直接执行java命令的时候可以通过参数-XX等来配置虚拟机的大小,同样,也应该留意到java -Dkey=value的参数.那么这个参数是什么作用呢? 使用案例 其实,在 ...
- Effective STL 学习笔记: Item 22 ~ 24
Effective STL 学习笔记: Item 22 ~ 24 */--> div.org-src-container { font-size: 85%; font-family: monos ...
- 一步一步学习IdentityServer3 (9)
idr添加验证码,授权方法中获取不到session,而且没有login页面的post方法,只有一个视图,而且是先加载视图,生成不了验证码 我的解决方法是将验证写一个自定义mvc控件 利用 viewd ...
- Java学习(正则表达式、Date类、DateFormat类、Calendar类)
一.正则表达式 1.概念:英语:Regular Expression,在代码中常简写为regex.正则表达式,是一个字符串,使用单个字符串来描述.用来定义匹配规则,匹配一系列符合某个句法规则的字符串. ...
- 在ASP.NET Web API和ASP.NET Web MVC中使用Ninject
先附上源码下载地址 一.准备工作 1.新建一个名为MvcDemo的空解决方案 2.新建一个名为MvcDemo.WebUI的空MVC应用程序 3.使用NuGet安装Ninject库 二.在ASP.N ...