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 i(1 ≤ 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[j]表示j这个时候最多能打怪物的血量,那么利用完全背包可以得到dp[j]=max(dp[j],dp[j-t[i]]+(j-t[i])*l[i]),其中dp[j-t[i]]是因为刚开始制造要花t[i]时间,后面指的是制造出来后的每一秒可以打多少血。

#include<stdio.h>
#include<string.h>
int max(int a,int b){
return a>b?a:b;
}
int dp[500];
int main()
{
int n,m=490,last,i,j;
int t[50],l[50];
while(scanf("%d%d",&n,&last)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%d%d",&t[i],&l[i]);
}
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++){
for(j=t[i];j<=m;j++){
dp[j]=max(dp[j],dp[j-t[i]]+(j-t[i])*l[i]);
}
}
for(i=1;i<=m;i++){
if(dp[i]>=last){
printf("%d\n",i);break;
}
}
}
return 0;
}

zoj3623 Battle Ships的更多相关文章

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

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

  2. zoj3623 Battle Ships ——完全背包?简单DP!|| 泛化背包

    link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 看起来像完全背包,但是物品价值是变化的,所以很多人搞的很复 ...

  3. Codeforces 567D One-Dimensional Battle Ships

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

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

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

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

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

  7. [ZOJ 3623] Battle Ships

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

  8. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  9. Battle ships(二分图,建图,好题)

    Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

随机推荐

  1. 【Linux】salt的cmd.script命令介绍

    salt是一个很棒的自动化运维工具之一,常用的有cmd.run,今天介绍的是cmd.script 其实一眼就能看出这个命令是执行脚本的命令 具体操作如下: 1.将/etc/salt/master中的 ...

  2. 如何查看U盘的VID和PID

    1.将USB插入电脑 2.右键单击[此电脑],选择[管理] 3.在弹出的对话框中选择[设备管理器],选择[USB大容量存储设备] 4.右键单击[USB大容量存储设备],选择[属性],在弹出的对话框中选 ...

  3. Databricks 第8篇:把Azure Data Lake Storage Gen2 (ADLS Gen 2)挂载到DBFS

    DBFS使用dbutils实现存储服务的装载(mount.挂载),用户可以把Azure Data Lake Storage Gen2和Azure Blob Storage 账户装载到DBFS中.mou ...

  4. 小试牛刀ElasticSearch大数据聚合统计

    ElasticSearch相信有不少朋友都了解,即使没有了解过它那相信对ELK也有所认识E即是ElasticSearch.ElasticSearch最开始更多用于检索,作为一搜索的集群产品简单易用绝对 ...

  5. postgres模糊匹配大杀器

    ArteryBase-模糊匹配大杀器 问题背景 随着pg越来越强大,abase目前已经升级到5.0(postgresql10.4),目前abase5.0继承了全文检索插件(zhparser),使用全文 ...

  6. watchdog应用实例

    watchdog应用实例 By 鬼猫猫 20130504 http://www.cnblogs.com/muyr/ 实例:监测某文件夹,一旦文件夹里有文件,就把它剪切到其他服务器 import sys ...

  7. Linux系统使用lvm扩展根分区

    Linux系统使用lvm扩展根分区 背景:买的云主机虚拟机封装镜像是40G的系统盘,后期适用不规范或者其他需求需要扩展系统盘,而非挂载在一个盘至新建目录. 1.原本目录磁盘等信息: 2.使用vgdis ...

  8. Linux中LPC、RPC、IPC的区别

    其实这玩意儿就是纸老虎,将英文缩写翻译为中文就明白一半了. IPC:(Inter Process Communication )跨进程通信 这个概念泛指进程之间任何形式的通信行为,是个可以拿来到处套的 ...

  9. 理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng 高可用架构 今天

    理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng  高可用架构  今天

  10. maven打包三种方式

    https://blog.csdn.net/w820896059/article/details/80423143