Topic: Given a plane of some points, eat Mr. Bean from the origin, can only go right or upward, beg two eat Mr. Bean up to how many beans
Each point is split into two, with a flow rate of 1, and a cost of 1 sides;
If you can get to another point from one point, connect the out point of the previous point back to the point in the point
Run the cost stream. But it's obviously going to be tle.
If I can go to J,j to K, then obviously need not even i->k this edge this is a pruning
After adding this pruning may be WA so also to consider a point after several times of the situation
That is, each point from the in point to the out point and then a flow of 1, the cost of 0 of the Edge
After this, you'll be able to get past the pruning, but nothing's going to put this card out of the picture.
Ms can prove that complexity is the root of the square.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 4040# Define P1 (x) (((x) <<1)-1) #define P2 (x) ((x) <<1) #define S (n<<1|1) #define T (n+1<<1) #define INF 0x3f3f3f3fusing namespace Std;struct point{int X,y;bool operator < (const point &p) const{if (x! = p.x) return x &L T P.x;return y < p.y;} Friend istream& operator >> (istream& _,point &p) {scanf ("%d%d", &p.x,&p.y); return _;}} Points[m];struct abcd{int To,f,cost,next;} Table[4004004];int head[m],tot=1;int n,ans,a[m];void Add (int x,int y,int f,int cost) {Table[++tot].to=y;table[tot].f=f ; Table[tot].cost=cost;table[tot].next=head[x];head[x]=tot;} inline void Link (int x,int y,int f,int cost) {ADD (x,y,f,cost); ADD (y,x,0,-cost);} BOOL Edmonds_karp () {static int q[65540],f[m],cost[m],from[m];static unsigned short r,h;static bool V[m];int i;memset ( cost,0xef,sizeof cost); Cost[s]=0;f[s]=inf;f[t]=0;q[++r]=s;while (r!=h) {int x=q[++h];v[x]=0;for (i=head[x];i;i=table[i].next) if (table[i].f&&cost[x]+table[i].cost>cost[table[i].to]) {cost[table[i].to ]=cost[x]+table[i].cost;f[table[i].to]=min (F[X],TABLE[I].F); From[table[i].to]=i;if (!v[table[i].to]) v[table[i]. to]=1,q[++r]=table[i].to;}} if (!f[t]) return false;ans+=f[t]*cost[t];for (i=from[t];i;i=from[table[i^1].to]) table[i].f-=f[t],table[i^1].f+=f[ T];return true;} int main () {int i,j;cin>>n;for (i=1;i<=n;i++) cin>>points[i];sort (points+1,points+n+1); for (i=1;i< =n;i++) {A[i]=points[i].y;int temp=-1; Link (0,P1 (i), 1,0); Link (P2 (i), t,1,0); Link (P1 (i), P2 (i), 1, 1); Link (P1 (i), P2 (i), 1,0), for (j=i-1;j;j--) if (a[j]<=a[i]&&a[j]>temp) Temp=a[j],link (P2 (j), P1 (i), 2,0); *for (j=1;j<i;j++) if (A[j]<=a[i]) Link (P2 (j), P1 (i), 1,0); */}link (s,0,2,0); while (Edmonds_karp ());cout<< Ans<<endl;return 0;}
Bzoj 1930 Shoi2003 Pacman eating beans fee stream