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<