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 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[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的更多相关文章
- ZOJ3623:Battle Ships(全然背包)
Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense ...
- zoj3623 Battle Ships ——完全背包?简单DP!|| 泛化背包
link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 看起来像完全背包,但是物品价值是变化的,所以很多人搞的很复 ...
- 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 ...
- [ZOJ 3623] Battle Ships
Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which is s ...
- HDOJ 5093 Battle ships 二分图匹配
二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...
- Battle ships(二分图,建图,好题)
Battle ships Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
随机推荐
- SpringBoot同时接收单个对象和List<object>参数
最近做项目的有个需求,是把多个文件移动到另一个文件夹下,这需要把 新的文件夹id -- Long类型 多个文件的信息 -- List< Object > 类型 这两个参数传给后台,我的后台 ...
- Redis 设计与实现 10:五大数据类型之有序集合
有序集合 sorted set (下面我们叫zset 吧) 有两种编码方式:压缩列表 ziplist 和跳表 skiplist. 编码一:ziplist zset 在 ziplist 中,成员(mem ...
- leetcode 321. 拼接最大数(单调栈,分治,贪心)
题目链接 https://leetcode-cn.com/problems/create-maximum-number/ 思路: 心都写碎了.... 也许就是不适合吧.... 你是个好人... cla ...
- [Usaco2016 Dec]Moocast
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4749 可以对于每个点\(i\),往跟\(i\)距离小于等于\(p[i]\)的点\(j\)都 ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- JAVA中@Override的含义
@Override是伪代码,表示重写(当然不写也可以),不过写上有如下好处: 1.可以当注释用,方便阅读: 2.编译器可以给你验证@Override下面的方法名是否是你父类中所有的,如果没有则报错.例 ...
- Javadoc命令与API
Javadoc命令与API Javadoc工具会抽取类,成员,方法的文档注释生成与这个类配套的API帮助文档 Javadoc命令和文档注释小公司基本不用,但我们应养成良好的编码习惯,所以还是了解一下 ...
- websocket的应用---Django
websocket的应用---Django 1.长轮询 轮询:在前端通过写js实现.缺点:有延迟.服务器压力大. 就是客户端通过一定的时间间隔以频繁请求的方式向服务器发送请求,来保持客户端和服务器端的 ...
- 从ReentrantLock源码入手看锁的实现
写这篇确实挺伤脑筋的,是按部就班一行一行读,但是我想这么写估计很多没有接触过的可能就劝退了,很容易出现的一种现象就是看了后面忘了前面,而且很容易看了一行代码就一层层往下钻,这样不仅容易打击看源码的积极 ...
- (13)-Python3之--获取当前时间
1.导入datetime模块 import datetime 2.获取当前日期和时间 import datetime now_time = datetime.datetime.now() print( ...