ZOJ3623:Battle Ships(全然背包)
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 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
题意:
对方有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(全然背包)的更多相关文章
- zoj3623 Battle Ships ——完全背包?简单DP!|| 泛化背包
link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 看起来像完全背包,但是物品价值是变化的,所以很多人搞的很复 ...
- zoj3623 Battle Ships
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
- 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 ...
- HDOJ 5093 Battle ships 二分图匹配
二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
随机推荐
- 【读书笔记】iOS-网络-运行循环
运行循环是由类NSRunLoop表示的,有些线程可以让操作系统唤醒睡眠的线程以管理到来的事件,而运行循环则是这些线程的基本组件.运行循环是这样一种循环,可以在一个周期内调度任务并处理到来的事件.iOS ...
- 关于flex布局兼容
(做个记录) 一.W3C各个版本的flex 2009 version 标志:display: box; or a property that is box-{*} (eg. box-pack) 201 ...
- 全局 DOM 变量
全局 DOM 变量 你可能已经知道,声明一个全局变量(使用 var 或者不使用)的结果并不仅仅是创建一个全局变量,而且还会在 global 对象(在浏览器中为 window )中创建一个同名属性. 还 ...
- 数据库小组与UI小组第一次对接
时间:2018.6.1,21:30 ~ 23:00 人员:除黄志鹏外全体成员,因为黄志鹏临时有事 工作内容: 主要为数据库小组与UI第二组对接,并将成果汇总到github仓库.另外UI第一组重构了代码 ...
- 风险指针(Hazard Pointer) 内存空间共享模型
WiredTiger是一种高性能的开源存储引擎,现已在MongoDB中作为内模式应用.WiredTiger支持行存储.列存储两种存储模式,采用LSM Tree方式进行索引记录 WiredTiger支持 ...
- 一个能够编写、运行SQL查询并可视化结果的Web应用:SqlPad
SqlPad 是一个能够用于编写.运行 SQL 查询并可视化结果的 Web 应用.支持 PostgreSQL.MySQL 和 SQL Server.SqlPad 目前仅适合单个团队在内网中使用,它直接 ...
- HTTP的cookie
HTTP cookies,通常又称作"cookies",已经存在了很长时间,但是仍旧没有被予以充分的理解.首要的问题是存在了诸多误区,认为cookies是后门程序或病毒,或压根不知 ...
- orcl创建表及管理表
常用的字段数据类型: .字符串(varchar2(n)) n表示保存最大长度,基本200作用..整数(number(n)) n位的整数,也可用int代替.小数(number(n,m)) m为小数位,n ...
- 【转】Mysql学习---SQL的优化
[原文]https://www.toutiao.com/i6594314336913588743/ mysql如何处理亿级数据,第一个阶段--优化SQL语句 1.应尽量避免在 where 子句中使用! ...
- 题解 P1034 【矩形覆盖】
题面 在平面上有n个点(n≤50),每个点用一对整数坐标表示.例如:当n=4时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这些点可以用k个矩形(1≤ ...