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 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;
}

时间: 2024-10-06 23:33:18

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

ZOJ3623 Battle Ships (完全背包)

Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 ki

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 th

Battle Ships(完全背包)

Battle ShipsCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defens

nyist oj 311 全然背包 (动态规划经典题)

全然背包 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描写叙述 直接说题意,全然背包定义有N种物品和一个容量为V的背包.每种物品都有无限件可用.第i种物品的体积是c,价值是w. 求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大.本题要求是背包恰好装满背包时,求出最大价值总和是多少. 假设不能恰好装满背包,输出NO 输入 第一行: N 表示有多少组測试数据(N<7). 接下来每组測试数据的第一行有两个整数M.V. M表示物品种类的数目,V表示背

hdu 5093 Battle ships 最大二分匹配

Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 233 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible

UVA 10306 e-Coins(全然背包: 二维限制条件)

option=com_onlinejudge&Itemid=8&page=show_problem&problem=1247">http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1247 题意: 对于每一个例子.先给定两个数n,m,分别表示有n种硬币,对于每一种硬币有两个价值.分别记做x,y,题目要求从中

HDU1248 寒冰王座 【数学题】or【全然背包】

寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10550    Accepted Submission(s): 5355 Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,仅仅有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡骑

HDU 1114 Piggy-Bank 全然背包

Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action come