"BZOJ2039" "2009 National Training Team" employ personnel employed minimum cut

Source: Internet
Author: User

Reprint Please specify source:http://blog.csdn.net/vmurder/article/details/42651751

In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...


Minimum cutting experience:

First of all need a certain foundation to find this problem is the smallest cut, and put into thinking.

And then how to build the diagram:

The minimum cut is the first to calculate all the proceeds, and then through the network map to cut edge minus the partial weight value.

Earnings can sometimes bring negative values.

Then we need to think about what can bring the weights and what will be the right value conflict.

and the minimum cut chart is generally split into s set and t set considerations, that is to take and not take, someone/point select a or select B, etc.

This leads to conflict, which is the edge that needs to be cut.

Then we need to get the value of the ownership and loss listed, targeted mapping, and then check several cases:

For example, two people in the S set, all in the T set, a s B T, a t and so on, we see this will cut off which sides, lose what weight value.

If found wrong, can also be targeted to modify.


That's all you have to say.

Here's a map of the problem:

Point: Everyone a point, extra set Yuanhui point.

Side:

The source of all the benefits that this person can cause (as a result of hiring all people and then the income of the person)

Even two people are familiar with each other, er, test instructions problem.

It takes money to hire people to connect with them.


Analyze

Income/loss resulting from the employment and non-employment of a person,

Two persons employed, neither employed nor employed a cause of loss,

It's easy to understand the map.


Code:

#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define N 1005#define M 2001000#define LL long long#define inf 0x3f3f3f3f#define inf 0x3f3f3f3f3f3f3f3fllusi ng namespace Std;struct ksd{int v,next;long long Len; E[m];int head[n],cnt;inline void Add (int u,int v,long long len) {e[++cnt].v=v;e[cnt].len=len;e[cnt].next=head[u];head[ u]=cnt;} int S,t,d[n];queue<int>q;bool BFs () {memset (d,0,sizeof (d)), while (!q.empty ()) q.pop (); int I,u,v;q.push (s), D[s] =1;while (!q.empty ()) {U=q.front (), Q.pop (); for (I=head[u];i;i=e[i].next) {if (!d[v=e[i].v]&&e[i].len) {d[v]= D[u]+1;if (v==t) return 1;q.push (v);}} return 0;} Long long dinic (int x,long long flow) {if (x==t) return Flow;long long Remain=flow,k;int i,v;for (i=head[x];i&& Remain;i=e[i].next) {if (D[v=e[i].v]==d[x]+1&&e[i].len) {k=dinic (V,min (Remain,e[i].len)), if (!k) d[v]=0;e[i ].len-=k,e[i^1].len+=k;remain-=k;}} return flow-remain;} int N;long Long Cost[n],map[n][n],sum[n];long Long Res,maxflow;void Build () {int i,j,k;scanf ("%d", &n), for (i=1;i<=n;i++) scanf ("%lld", &cost[i]); for (i =1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%lld", &map[i][j]), Sum[i]+=map[i][j];cnt=1,s=n+1,t=n+2;for (i=1;i <=n;i++) Add (S,i,sum[i]), add (i,s,0), Res+=sum[i];for (i=1;i<=n;i++) Add (I,t,cost[i]), add (t,i,0); for (i=1;i <=n;i++) for (j=i+1;j<=n;j++) Add (I,j,2*map[i][j]), add (J,i,2*map[i][j]);} int main () {//freopen ("test.in", "R", stdin), build (), while (BFS ()) maxflow+=dinic (S,inf);p rintf ("%d\n", Res-maxflow); return 0;}




"BZOJ2039" "2009 National Training Team" employ personnel employed minimum cut

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.