HDU 3681 Prison Break floyd + pressure + binary

Source: Internet
Author: User

HDU 3681 Prison Break floyd + pressure + binary

Question link: Click the open link

Question:

Matrix given n * m:

F: Start Point (with only one)

D: Bad point (cannot reach this point)

G: energy pool (you can choose to use the energy pool at this point to fill the battery. You can also use it only once)

Y: Target Point

Q:

What is the minimum battery capacity required to traverse all Y points.

The battery starts to be fully powered, consuming one grid of electricity each step.

Y + G count <= 15. n, m <= 15

Idea: Pressure YG. the first digit represents Y, and the last digit represents G.

Run a floyd command first, then the battery capacity is second, And the dp command is feasible.

#include 
 
  #include 
  
   #include #include 
   
    #include 
    
     #include 
     
      using namespace std;const int inf = 5500;const int N = 15;struct node{    int x, y;    node(int a=0, int b=0):x(a),y(b){}}Y[N], G[N], P[N+1], F;int ynum, gnum, dp[1<
      
        qx, qy; qx.push(x); qy.push(y); while(!qx.empty()){ int ux = qx.front(); qx.pop(); int uy = qy.front(); qy.pop(); for(int i = 0; i < 4; i++) { int vx = step[i][0] + ux, vy = step[i][1] + uy; if(false == (0<=vx && vx 
       
         State, End; for(int i = 0; i < ynum; i++) if(power - dis[F.x][F.y][Y[i].x][Y[i].y] >= 0) { dp[1<
        
         = 0) { dp[1<<(i+ynum)][i+ynum] = power; State.push(1<<(i+ynum)); End.push(i+ynum); } while(!State.empty()) { int s = State.front(); State.pop(); int e = End.front(); End.pop(); if((s & ((1<
         
          = ((1<
          
           >n>>m, n+m){ input(); if(ynum == 0){puts("0");continue;} floyd(); int ans = inf, l = 0, r = inf; while(l <= r){ int mid = (l+r)>>1; if(ok(mid)) r = mid-1, ans = min(ans, mid); else l = mid+1; } if(ans == inf) ans = -1; cout<
           

Related Article

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.