ZOJ3623 Battle Ships (full backpack)

Source: Internet
Author: User
Tags cmath

ZOJ3623 Battle Ships (full backpack)

 

Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB

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

There are n types of ships that provide the time to create each type of ship and how much blood the ship can take in one second. The total blood volume is given and the minimum number of seconds required to hit the ship.

 

If dp [I] is set to indicate the maximum number of drops of blood that can be destroyed in the second I, then the answer is to start enumeration from 0th seconds and find the first one that is greater than or equal to L.

 

Dp [j + t [I] = max {dp [I + t [I], dp [j] + l [I] * j}

 

 

 

#include #include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include
      #include 
       
        #include 
        
         #include 
         
          //#include 
          
           #define MAX 0x3f3f3f3f#define N 100005#define M 200005#define mod 1000000007#define lson o<<1, l, m#define rson o<<1|1, m+1, rtypedef long long LL;using namespace std;const double pi = acos(-1.0);int n, m;int t[40], l[40], dp[40000];int main(){ //freopen("in.txt","r",stdin); while(~scanf("%d%d", &n, &m)) { for(int i = 0; i < n; i++) { scanf("%d%d", &t[i], &l[i]); } memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i++) { for(int j = 0; j <= 340; j++) { dp[ t[i] + j ] = max(dp[ t[i] + j ], dp[j] + j*l[i]); } } for(int i = 0; i < 400; i++) { if(dp[i] >= m) { printf("%d\n", i); break; } } }return 0;}
          
         
        
       
     
    
   
  
 

 

 

 

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.