Bzoj 3144 Hnoi 2013 cut Cake min cut

Source: Internet
Author: User

The main idea: to give a three-dimensional lattice, not a point is likely to be cut, the price is the weight of this point. The height difference of the adjacent cutting points cannot exceed D, and the minimum cost makes the top and bottom separate.


Idea: Very bare minimum cut model, very God-built map.

S-> the first floor, F:inf.

All points--the dots below it, f:inf

A point of entry-and-out of a point, f:val[i]

(i,j,k)-> (i-d,j,k), F:inf

The bottom layer of the dot->t:f:inf

Then the smallest cut is the answer.

Why see: Http://www.cnblogs.com/zyfzyf/p/4182168.html Otz ZYF


CODE:

#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define MAX 130000#define maxe 1200000#define S 0#define T (MAX-1) #define INF 0x3f3f3f3fusing namespace std ; const int dx[] = {0,1,-1,0,0};const int dy[] = {0,0,0,1,-1};struct maxflow{int head[max],total;int next[maxe],aim[maxe], Flow[maxe];int Deep[max]; Maxflow () {total = 1;memset (head,0,sizeof (Head));} void Add (int x,int y,int f) {next[++total] = head[x];aim[total] = Y;flow[total] = f;head[x] = total;} void Insert (int x,int y,int f) {Add (x,y,f); ADD (y,x,0);} BOOL BFS () {static queue<int> Q;while (!q.empty ()) Q.pop () memset (deep,0,sizeof (deep));d eep[s] = 1;q.push (S); while (!q.empty ()) {int x = Q.front (), Q.pop (), for (int i = head[x]; i; i = Next[i]) if (Flow[i] &&!deep[aim[i]) {de Ep[aim[i]] = deep[x] + 1;q.push (Aim[i]), if (aim[i] = = T) return true;}} return false;} int dinic (int x,int f) {if (x = = T) return F;int temp = f;for (int i = head[x]; i; i = Next[i]) if (flow[I] && temp && deep[aim[i]] = = Deep[x] + 1) {int away = Dinic (Aim[i],min (flow[i],temp)); if (!away) deep[aim[i ]] = 0;flow[i]-= away;flow[i^1] + = away;temp-= away;} return f-temp;}} Solver;int p,q,r,d;int Src[50][50][50],num[50][50][50],cnt;int Main () {cin >> P >> Q >> R >> d;for (int i = 1; I <= R; ++i) for (int j = 1; j <= P; ++j) for (int k = 1; k <= Q; ++k) {scanf ("%d", &src[i][j][k]), num I [j] [K] = ++cnt;solver. Insert (Num[i][j][k] << 1,num[i][j][k] << 1|1,src[i][j][k]);} for (int i = 1, i <= P; ++i) for (int j = 1; j <= Q; ++j) {solver. Insert (S,num[1][i][j] << 1,inf); Solver. Insert (Num[r][i][j] << 1|1,t,inf);} for (int i = 1, i <= R; ++i) for (int j = 1, J <= P; ++j) for (int k = 1; k <= Q; ++k) {if (i! = R) solver. Insert (Num[i][j][k] << 1|1,num[i + 1][j][k] << 1,inf); for (int d = 1; d <= 4; ++d) {int FX = j + dx[d],fy = K + dy[d];if (!fx | |!fy | | FX > P | | fy > Q) continue;if (i-d > 0) solvEr. Insert (Num[i][j][k] << 1,num[i-d][fx][fy] << 1,inf);}} int max_flow = 0;while (solver. BFS ()) Max_flow + = Solver. Dinic (S,inf); cout << Max_flow << endl;return 0;}


Bzoj 3144 Hnoi 2013 cut Cake min cut

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.