SDUToj3005 upgrade (memory-based search)

Source: Internet
Author: User
What should I do if the number of multiplication 2 is huge during the competition? the array cannot be opened... Later, I found myself stupid. The maximum number is 10. The maximum power is 100 .... The other is the memory-based search, and the other is that the bottle with a little power will be used at that time. TimeLimit: 1000 ms & #160; & #160; Memorylimit: 262144 K & #1

What should I do if the number of multiplication 2 is huge during the competition? the array cannot be opened... Later, I found myself stupid. The maximum number is 10. The maximum power is 100 ....

The other is the memory-based search, and the other is that the bottle with a little power will be used at that time.


Strange upgrade Time Limit: 1000 ms Memory limit: 262144 K Any Questions? Click here ^_^ Description

For most RPG games, apart from the plot, it is a strange upgrade. The task of this question is to win all battles in the shortest time. These battles must be carried out in a specific order. each time you win a battle, you may get some supplements to improve your strength. There are only two kinds of supplements in this question: "Add 1 medicine" and "Take 2 medicine", respectively, let your power value add 1 and multiply by 2. The combat time depends on your strength. Each battle can be described with six parameters: p1, p2, t1, t2, w1, w2. If your power is less than p1, you will lose the battle; if your power is greater than p2, it takes t2 seconds to win the battle; if the power is at p1 and p2 (including p1 and p2 ), the combat time decreases linearly from t1 to t2. For example, if p1 = 50, p2 = 75, t1 = 40, t2 = 15, and your strength is 55, it takes 35 seconds to win the battle. Note that the combat time may not be an integer. The last two parameters w1 and w2 indicate the numbers of "add 1 medicine" and "Take 2 medicine" obtained after victory. Note that you do not have to use these supplements immediately. you can use them as needed, but you cannot use them in battle. Parameters for each battle are provided in sequence, and the minimum total time required to win all battles is output. The battle must be in order and cannot skip any battle.

Input

The input can contain up to 25 groups of test data. The first behavior of each group of data is two integers, n and p (1 <= n <= 1000, 1 <= p <= 100), that is, the number of battle sites and your initial strength value. The following n rows have 6 integers in each row: p1, p2, t1, t2, w1, w2 (1 <= p11 <= p1 Output

For each group of data, the minimum total output time (unit: seconds) is retained with two decimal places. If there is no solution, output "Impossible" (excluding quotation marks ).

Sample input
1 5550 75 40 15 10 02 5550 75 40 15 10 050 75 40 15 10 03 11 2 2 1 0 51 2 2 1 1 01 100 100 1 0 01 74 15 35 23 0 01 12 3 2 1 0 00 0
Sample output
35.0060.0041.0031.73Impossible
Prompt
#include 
 
  #include 
  #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include using namespace std;const int maxn = 1010;const double INF = 100000000.0;struct node{ int p1, p2, t1, t2, w1, w2;}f[maxn];int n;double dp[maxn][110][15];double distime(node a, int x){ if(x >= a.p2) return a.t2*1.0; double x1 = a.p1*1.0; double y1 = a.t1*1.0; double x2 = a.p2*1.0; double y2 = a.t2*1.0; double x3 = x*1.0; return (x3*((y1-y2)/(x1-x2)) + (y1-x1*((y1-y2)/(x1-x2))));}double dfs(int x, int w, int num){ if(x > n) return 0; if(dp[x][w][num] > -1.0) return dp[x][w][num]; if(w < f[x].p1) { while(w < f[x].p2 && num) { w = min(100, w*2); num--; } } if(w < f[x].p1) { dp[x][w][num] = INF; return dp[x][w][num]; } dp[x][w][num] = INF; for(int i = 0; i <= num; i++) dp[x][w][num] = min(dp[x][w][num], distime(f[x], w<
            
             

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.