https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=3916
This problem requires a filling + digging pit + building barrier method, so that the land on all the pits and grass between all the barriers, digging pit spend d per block, fill the cost f per block, build the barrier cost B every two pieces, attention does not require there must be pits, but the periphery of a lap must be no pits, so need to pre-fill good
Make St represents the flat, Ed stands for the pit, the right side for the cost, then the subject is to require a st-ed minimum cut, because s to the flat cost of 0, so do not build the edge, the same pit to Ed does not need to spend not to build the edge, each point to the adjacent point to build the edge, the capacity of the b,s to the To prevent the perimeter from being dug, the capacity is set to INF.
With St as the starting point, Ed as the end point, to find the maximum flow, that is, the smallest cut can
The problem at the beginning of the thought is DP, in fact, is a minimum cut, although there are 2,500 points, 50,000 sides around, but still can use the network flow, a start to think about how to deal with the barrier, but in fact, only need to each point and adjacent points are connected to each other, the horizontal flow of no meaning, This means that only the edge between the flat and the pit will limit the flow.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn=5000; const int Maxm=5000000;const int inf=0x3fffffff;int first[maxn];struct edge{int nxt,from,t,f,c;} E[maxm];int w,h,d,fl,b,len;char maz[60][60];const int dx[4]={1,-1,0,0};const int Dy[4]={0,0,1,-1};int st,ed,num;int Dis[maxn],gap[maxn];bool in (int x,int y) {return x>=0&&x
Uvalive 5905 Pool Construction min Cut, s-t cut nature Difficulty: 3