Battle ships (full backpack)

Source: Internet
Author: User

Battle shipsCrawling in process...Crawling failedTime limit:2000 msMemory limit:65536kb64bit Io format:% LLD & % LlU

Submitstatus

Description

Battle shipsIs a new game which is similarStar Craft. In this game, the enemy builds a defense Tower, which hasLLongevity. the player has a military factory, which can produceNKinds of battle ships. The factory takesTiSeconds to produceI-Th battle ship and this battle ship can make the tower lossLiLongevity 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 shocould spend to win the game.

Input

There are multiple test cases.
The first line of each case contains two integersN(1 ≤N≤ 30) andL(1 ≤L≤ 330 ),NIs the number of the kinds of battle ships,LIs the longevity of the Defense tower. Then the followingNLines, each line contains two integersT I(1 ≤T I≤ 20) andLi(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 shocould spend to win the game.

Sample Input

1 11 12 101 12 53 1001 103 2010 100

Sample output

245
 
Create a baby monster with a blood volume of L. You can create N types of towers. Each tower takes Ti seconds to obtain blood from AI. The minimum number of seconds to kill a monster. Idea: Take time as the capacity and the total volume of injury as the value. Because a tower can cause damage every second after construction, the order of building the same tower will affect the final result.
 
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <queue>#include <string>using namespace std;#define inf 99999999int main(){    int dp[400];    int t[40],l[40];    int N,L,i,j;    int cnt;    while(~scanf("%d %d",&N,&L))    {        memset(dp,0,sizeof(dp));        for(i=0; i<N; i++)            scanf("%d %d",&t[i],&l[i]);        cnt=inf;        for(i=0; i<N; i++)        {            for(j=t[i];j;j++)            {                dp[j]=max(dp[j],dp[j-t[i]]+(j-t[i])*l[i]);               if(dp[j]>=L)                break;            }            if(cnt>j)                cnt=j;        }        printf("%d\n",cnt);    }    return 0;}

Zookeeper

Battle ships (full backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.