BZOJ2039: [Employment of 2009 national training Team]employ personnel

Source: Internet
Author: User

Exercises

Consider the minimum cut. It is advisable to set S cut as not selected and T cut for selection.

The Edge (S,i,a[i]) (I,t,b[i]) b[i] represents the sum of the contributions I make to other points.

The meaning obviously, if I belong to S-cut, need to pay b[i] price, if I belong to T cut, need to pay a[i] price.

Then for E[i][j], the Edge (I,j,2*e[i][j]) (J,i,2*e[i][j]) refers to the cost when the two points are not in the same cut.

The minimum cost is calculated by the minimum cutting weight without leakage.

With the proceeds and minus the minimum cut is the answer.

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 100000000000000LL - #defineMAXN 100000+5 - #defineMAXM 1100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; - inline ll read () - { -ll x=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intn,m,s,t,tot=1, HEAD[MAXN],CUR[MAXN],H[MAXN]; -queue<int>Q; the ll MAXFLOW,SUM,A[MAXN],B[MAXN]; * structedge{intGo,next;ll v;} e[2*MAXM]; $ voidAddintXintY,ll v)Panax Notoginseng { -E[++tot]= (Edge) {y,head[x],v};head[x]=tot; theE[++tot]= (Edge) {X,head[y],0};head[y]=tot; + } A BOOLBFS () the { +      for(inti=s;i<=t;i++) h[i]=-1; -Q.push (s); h[s]=0; $      while(!q.empty ()) $     { -         intx=Q.front (); Q.pop (); -          for(intI=head[x];i;i=e[i].next) the          if(e[i].v&&h[e[i].go]==-1) -          {Wuyih[e[i].go]=h[x]+1; Q.push (e[i].go); the          } -     } Wu     returnh[t]!=-1; - } Aboutll Dfs (intx,ll f) $ { -     if(x==t)returnF; -ll tmp,used=0; -      for(intI=cur[x];i;i=e[i].next) A      if(e[i].v&&h[e[i].go]==h[x]+1) +     { theTmp=dfs (E[i].go,min (e[i].v,f-used)); -e[i].v-=tmp;if(E[I].V) cur[x]=i; $e[i^1].v+=tmp;used+=tmp; the         if(used==f)returnF;  the     } the     if(!used) h[x]=-1; the     returnused; - } in voiddinic () the { themaxflow=0; About      while(BFS ()) the     { the          for(inti=s;i<=t;i++) cur[i]=head[i];maxflow+=DFS (s,inf); the     } + } - intMain () the {BayiFreopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); theN=read (); s=0; t=n+1; -For1 (i,n) a[i]=read (); - For1 (i,n) For1 (j,n) the     { thell X=read (); sum+=x;b[i]+=x; the         if(I==J)Continue; theAdd (I,j, (LL)2*x); -     } the For1 (i,n) Add (S,i,a[i]), add (I,t,b[i]); the dinic (); thecout<<sum-maxflow<<Endl;94     return 0; the}
View Code 2039: [2009 National training Team]employ personnel hire time limit:20 Sec Memory limit:259 MB
submit:574 solved:280
[Submit] [Status] Description

As a wealthy business-minded millionaire, small L decided to hire some of the best managers in the country to run his own company. These managers have a contribution index to each other, (we use EI,J to show how much I managers know about J Manager), that is, when manager I and manager J are employed, manager I will contribute to manager J, making the profit gain ei,j. Of course, hiring every manager will cost a certain amount of money AI, and for some managers it may not be worth the cost of his contribution, so as a smart man, little l will certainly not hire him. However, those who are not hired will be hired by competitors, who will have an impact on the job of the manager you are hiring, making the profits less ei,j (note: The ei,j here is the same as the ei,j above). As an efficiency priority, small l wanted to hire some people to make the net profit the most. Can you help small l solve this problem?

Input

The first line has an integer n<=1000 that indicates the number of managers the second line has n integers. ai indicates the amount of money to be spent on hiring each manager. The next n rows contain n numbers, representing Ei,j, which is how well manager I understands manager J. (Input satisfies ei,j=ej,i)

Output

The first line contains an integer, which is the maximum value that is calculated.

Sample Input3
3 5 100
0 6 1
6 0 2
1 2 0
Sample Output1
"Data size and conventions"
20% of the data in n<=10
50% of the data in n<=100
100% of data in n<=1000, Ei,j<=maxlongint, Ai<=maxlongint
HINT Source

Copyright owner: Lin Yuakei

BZOJ2039: [Employment of 2009 national training Team]employ personnel

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.