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 ...
随机推荐
- 八、springboot整合redis
整合Redis 一. 注解方式实现添加缓存 1.在pom.xml加入依赖 <!-- 配置使用redis启动器 --> <dependency> <groupId>o ...
- nvm npm node.js的关系
nvm npm node.js都是用来构建reactNativ的项目 nvm管理node.j和npm版本的 node.js管理reactNative开发中所需要的代码库的 npm管理对应node ...
- 关于 JVM 内存的 N 个问题(转)
JVM的内存区域是怎么划分的? JVM的内存划分中,有部分区域是线程私有的,有部分是属于整个JVM进程:有些区域会抛出OOM异常,有些则不会,了解JVM的内存区域划分以及特征,是定位线上内存问题的基础 ...
- python面向对象(六)之元类
元类 1. 类也是对象 在大多数编程语言中,类就是一组用来描述如何生成一个对象的代码段.在Python中这一点仍然成立: In [13]: class ObjectCreator(object): . ...
- No.9 selenium学习之路之CSS定位
CSS定位方式: 元素中间加“.”表示是class 1.通过ID定位 driver.find_element_by_css_selector("#ID值") 2.通过class定位 ...
- HDU 1054 Strategic Game(最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...
- Effective STL 学习笔记: Item 22 ~ 24
Effective STL 学习笔记: Item 22 ~ 24 */--> div.org-src-container { font-size: 85%; font-family: monos ...
- Java字符串常见实例与函数
字符串比较 字符串函数 compareTo (string) ,compareToIgnoreCase(String) 及 compareTo(object string) 来比较两个字符串,并返回字 ...
- PHP5.6中php-fpm的配置、启动、关闭和重启
转:http://blog.csdn.net/field_yang/article/details/52401994 该文主要讲述:如何配置PHP-fpm.常见报错解决方法和php-fpm的启动.关闭 ...
- SourceTree 3.0.17如何跳过注册进行安装? — git图形化工具(一)
SourceTree 3.0.17个人版本的尝试跳过注册方式好几次都没成功,于是下载了企业版本https://www.sourcetreeapp.com/enterprise. 安装过程: 1.首次点 ...