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

题意:
对方有L滴血,我们有n种船能够选择。每种船建造时间为t,建好后每秒对敌方造成l点伤害,问最少多少时间能干掉对方

思路:
以时间为容量来进行背包

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define inf 1<<30
int dp[10000],t[100],l[100]; int main()
{
int n,m,i,j,sum = 6600,ans;
while(~scanf("%d%d",&n,&m))
{
for(i = 0; i<n; i++)
scanf("%d%d",&t[i],&l[i]);
memset(dp,0,sizeof(dp));
for(j = 0; j<333; j++)
{
for(i = 0; i<n; i++)
{
dp[j+t[i]] = max(dp[j+t[i]],dp[j]+j*l[i]);
}
}
ans = inf;
for(i = 0; i<333; i++)
{
if(dp[i]>=m)
{
ans=min(ans,i);
}
}
printf("%d\n",ans);
} return 0;
}

ZOJ3623:Battle Ships(全然背包)的更多相关文章

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

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

  2. zoj3623 Battle Ships

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

  3. [ZOJ 3623] Battle Ships

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

  4. Codeforces 567D One-Dimensional Battle Ships

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

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

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

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

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

  8. HDOJ 5093 Battle ships 二分图匹配

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

  9. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

随机推荐

  1. Flutter——设置appBar的高度

    使用脚手架Scaffold可以设置AppBar,想要设置高度,在AppBar外包一层PreferredSize,设置preferredSize的属性为想要的高度即可. Scaffold( appBar ...

  2. Android--解决EditText放到popupWindow中,原有复制、粘贴、全选、选择功能失效问题

    1.原来是将EditView放到了popupwindow,发现EditView原有的复制.粘贴.全选.选择功能失效了,所以便用DialogFragment代替了popupWindow 直接上代码 ①. ...

  3. Maven入门详情

    Maven的作用 在开发中,为了保证编译通过,我们会到处去寻找jar包,当编译通过了,运行的时候,却发现"ClassNotFoundException",我们想到的是,难道还差ja ...

  4. Oracle EBS AR 贷项通知单核销取值

    SELECT cm.trx_number ,fnd_flex_ext.get_segs('SQLGL', 'GL#', gcc.chart_of_accounts_id, ad.code_combin ...

  5. javascript 正则(将数字转化为三位分隔的样式)【转】

    原文:https://www.cnblogs.com/sivkun/p/7123963.html })+\b)/g, ',') 解释: \b : 匹配单词边界,就是位于字符\w([a-zA-Z0-9_ ...

  6. Difference between HashMap and Hashtable | HashMap Vs Hashtable

    Both the HashMap and Hashtable implement the interface java.util.Map but there are some slight diffe ...

  7. 脱壳_00_压缩壳_ASPACK

    写在前面的话: Aspack是最常见的一种压缩壳,具有较好的兼容性.压缩率和稳定性,今天我们就来一起分析一下这个壳: 零.分析压缩壳: 0.在开始动态调试前,用PEID和LoadPE查看一些信息,做到 ...

  8. oracle数据库中如何去除空格

    目前,我所知道的就有两种方法: 一.trim(a)--只能去除字符串左右的空格 select trim(leading from ' ——11—— ') aa from dual; select tr ...

  9. Windows server 安装和配置zabbix agent

    1.下载Windows 平台的zabbix agent 先到官网下载zabbix_agentd监控客户端软件安装包(windows操作系统客户端),客户端版本尽量与服务器版本一致,下载地址:http: ...

  10. String、StringBuffer与StringBuilder的区别-陈远波

    String Stringbuffer  StringBuilder的区别: 1.string是字符串常量,且长度是不可改变的,Stringbuffer.stringBuilder是字符串变量 2.S ...