B - Battle Ships

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Appoint description:
 

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的更多相关文章

  1. [ZOJ 3623] Battle Ships

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

  2. ZOJ 3623 Battle Ships 简单DP

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 题意:给出N种可以建造的船和对方的塔生命值L,每种船给出建造时 ...

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

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

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

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

  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. Codeforces 567D One-Dimensional Battle Ships

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

  7. 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 ...

  8. HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)

    Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...

  9. 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 ...

随机推荐

  1. Python和MySQL数据库交互PyMySQL

    Python数据库操作 对于关系型数据库的访问,Python社区已经指定了一个标准,称为Python Database API SepcificationV2.0.MySQL.Qracle等特定数据库 ...

  2. ActiveMQ 使用场景

    ActiveMQ 安装测试就不做介绍了,下面我说说ActiveMQ 使用场景.(松耦合与ActiveMQ) 1.非均匀应用集成 ActiveMQ 中间件用Java语言编写,因此自然提供Java客户端 ...

  3. 二十、springboot之jpa开发@MappedSuperclass 注解说明

    @MappedSuperclass使用条件: 当我们进行开发项目时,我们经常会用到实体映射到数据库表的操作,此时我们经常会发现在我们需要映射的几个实体类中,有几个共同的属性,例如编号ID,创建者,创建 ...

  4. 监听 手机back键和顶部的回退

    // 回退事件,监听 手机back键和顶部的回退 pushHistory(); window.addEventListener("popstate", function(e) { ...

  5. OpenCV 颜色空间转换参数CV_BGR2GRAY改变

    OpenCV的颜色空间转换函数:   C++: void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0 )   参数d ...

  6. 【POJ】2165.Gunman

    题解 把直线的斜率分解成二维,也就是随着z的增加x的增量和y的增量 我们发现一条合法直线向上移一点一定能碰到一条横线 知道了这条横线可以算出y的斜率 我们旋转一下,让这条横线碰到两条竖线,就可以算出x ...

  7. Educational Codeforces Round 45 (Rated for Div. 2) E - Post Lamps

    E - Post Lamps 思路:一开始看错题,以为一个地方不能重复覆盖,我一想值这不是sb题吗,直接每个power check一下就好....复杂度nlogn 然后发现不是,这样的话,对于每个po ...

  8. linux虚拟机更改时区

    第一种方法: cat  /etc/sysconfig/clock ZONE="Asia/Shanghai" UTC=true ARC=false rm   -f /etc/loca ...

  9. 黑马程序员_java基础笔记(12)...内省(IntroSpector)

    —————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流!—————————— 1,了解JavaBean.2,BeanUtils工具包. 1,了解JavaBean. ...

  10. Collabtive 系统 SQL 注入实验(补充)

    SQL Injection:就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 具体来说,它是利用现有应用程序,将(恶意)的SQL命令注 ...