BZOJ2039[2009 National Training Team]EMPLOY personnel employment

Source: Internet
Author: User

BZOJ2039[2009 National Training Team]EMPLOY personnel employment

Test instructions

There are n managers, Ei,j said I manager to J manager's understanding degree, when manager I and manager J is also employed, profit increase ei,j*2. At the same time, hiring every manager has to spend a certain amount of money on AI. People who are not hired will be hired by rivals to reduce the profit ei,j (meaning that managers I and J will be less ei,j if they hire only one, and if two are not hired, no money is deducted). Maximum profit. n≤1000

Exercises

The S-set represents employment, and the T-set indicates no employment. Each manager is split into X, y two points. S is connected to all x points and the flow rate is the cost of employment. For each ei,j,i,j manager with a flow of 2*ei,j of the non-forward edge, while I and J are to the t even flow to the ei,j edge, the minimum cut for all ei,j*2 minus the maximum flow. Because of the large number of sides, you need to merge one bottom.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineMAXN 11006 #defineInc (I,J,K) for (int i=j;i<=k;i++)7 #defineINF 10000000000000000008 #definell Long Long9 using namespacestd;Ten  One structe{intT;ll C;intn;}; E es[maxn* -];intg[maxn],ess; AInlinevoidPeintFintt,ll c) { -Es[++ess]= (e) {t,c,g[f]}; g[f]=ess; Es[++ess]= (e) {f,0, G[t]}; g[t]=ess; - } theInlinevoidPe2 (intFintt,ll c) { -Es[++ess]= (e) {t,c,g[f]}; g[f]=ess; Es[++ess]= (e) {f,c,g[t]}; g[t]=ess; - } -Inlinevoidinit () { +ess=-1; memset (g,-1,sizeof(g)); - } +Queue <int> q;intH[MAXN]; A BOOLBFsintSintt) { atmemset (h,-1,sizeof(h)); while(!q.empty ()) Q.pop (); h[s]=0; Q.push (s); -      while(!Q.empty ()) { -         intx=Q.front (); Q.pop (); -          for(inti=g[x];i!=-1; i=es[i].n)if(es[i].c&&h[es[i].t]==-1) h[es[i].t]=h[x]+1, Q.push (es[i].t); -     } -     returnh[t]!=-1; in } -ll Dfs (intXintT,ll F) { to     if(x==t)returnF ll u=0; +      for(inti=g[x];i!=-1; i=es[i].n)if(es[i].c&&h[es[i].t]==h[x]+1){ -ll W=dfs (Es[i].t,t,min (F,ES[I].C)); F-=w; U+=w; Es[i].c-=w; es[i^1].c+=w;if(f==0)returnu; the     } *     if(u==0) h[x]=-1;returnu; $ }Panax NotoginsengLL Dinic (intSintt) { -ll f=0; while(BFS (s,t)) F+=dfs (S,t,inf);returnF; the } + intn,s,t; ll A[maxn],b,tot; A intMain () { thescanf"%d", &n); s=0; t=n+1; Init (); Inc (I,1, N) scanf ("%lld", &b), PE (S,I,B); Memset (A,0,sizeof(a)); +Inc (I,1, N) Inc (J,1, N) { -scanf"%lld", &b);if(i>j| | b==0)Continue; A[i]+=b; A[j]+=b; Pe2 (I,j,2*B); tot+=2*b; $     } $Inc (I,1, n) PE (i,t,a[i]); printf"%lld", Tot-dinic (s,t));return 0; -}

20160530

BZOJ2039[2009 National Training Team]EMPLOY personnel employment

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.