The problem model out of the true God.
It needs to be very difficult to roll out.
Originally intended to write a good problem, but the state is not good, did not get this question.
You can only leave a hole in the building.
It is said that the "simplex algorithm" can be high-speed + bare-figure water over this problem (er, or the problem is a simplex naked question is also. )
Stay Pits before you give a link, it should be the best problem on the Internet now:
the byv of the Great God:www.byvoid.com/blog/noi-2008-employee/#more-916
My Code:
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" > #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define N 1050#define M 30100#define P 105#define inf 0x3f3f3f3fusing namespace std;struct ksd{int U,v,len,fe E,next;} E[m];int head[n],cnt;void Add (int u,int v,int len,int fee) {Cnt++;e[cnt].u=u;e[cnt].v=v;e[cnt].len=len;e[cnt].fee=fee ; e[cnt].next=head[u];head[u]=cnt;} int S,t,dist[n];int pre[n],lim[n];bool in[n];queue<int>q;void spfa () {memset (dist,0x3f,sizeof (Dist)); Memset ( Lim,0,sizeof (Lim)), while (!q.empty ()) Q.pop (), int i,u,v;dist[s]=0,in[s]=1;lim[s]=inf;q.push (s), while (!q.empty ()) { U=q.front (), Q.pop (), In[u]=0;for (I=head[u];i;i=e[i].next) {v=e[i].v;if (!e[i].len) continue;if (dist[v]>dist[u]+ E[i].fee) {dist[v]=dist[u]+e[i].fee;lim[v]=min (E[i].len,lim[u]);p re[v]=i;if (!in[v]) {In[v]=1;q.push (v);}}} return;} void handle (int flow) {for (int i=pre[t];i;i=pre[e[i].u]) {e[i].len-=flow;e[i^1].len+=flow;}} int N,m,minfee; int Need[n];int Main () {//freopen ("test.in", "R", stdin), int i,a,b,c;scanf ("%d%d", &n,&m), n++;s=n+1,t=n+2, Cnt=1;for (i=1;i<n;i++) scanf ("%d", &need[i]); for (i=1;i<=m;i++) {scanf ("%d%d%d", &a,&b,&c); Add (A,b+1,inf,c), add (b+1,a,0,-c);} for (i=1;i<=n;i++) {c=need[i]-need[i-1];if (c>=0) Add (s,i,c,0), add (i,s,0,0), else Add (i,t,-c,0), add (t,i,0,0); if (i>1) Add (i,i-1,inf,0), add (i-1,i,0,0);} while (SPFA (), Dist[t]<inf) {minfee+=dist[t]*lim[t];handle (lim[t]);} printf ("%d\n", Minfee); return 0;} </span>
"BZOJ1061" "NOI2008" volunteer recruitment cost flow divine question, simplex nude question (code cost flow)