[BZOJ1061] [Noi2008] Volunteer recruitment (fee flow)

Source: Internet
Author: User

DescriptionAfter the successful bid, Bubu after unremitting efforts, and finally become the head of the organization's human resources department. Bubu has just come into a dilemma: recruiting short-term volunteers for the upcoming new Olympic project. It is estimated that the project will take n days to complete, with the first day I need an AI person at least. Bubu learned by understanding that there are altogether m-type volunteers can recruit. In which class I can work from Si days to ti days, the recruitment fee is per person ci yuan. In order to do his job well, Bubu hopes to recruit enough volunteers with as little money as possible, but this is not his specialty! So Bubu found you, I hope you help him design an optimal recruitment program.InputThe first line contains two integers n, M, indicating the number of days to complete the project and the types of volunteers that can be recruited. The next line contains n non-negative integers, representing at least the number of volunteers needed per day. The next M-line contains three integers of Si, Ti, Ci, meaning as described above. For the sake of convenience, we can assume that the number of each type of volunteer is infinitely large.Output

Contains only an integer representing the total cost of the optimal scheme you have designed.

Sample Input3 3
2 3 4
1 2 2
2 3 5
3 3 2Sample Output -HINT

1≤n≤1000,1≤m≤10000, the other data involved in the topic are not more than 2^31-1.

SourceSolution

The number of $i$ volunteers is $x_{i}$, so we have an inequality: (in the sample description)

$x _{1}\geq2$

$x _{1}+x_{2}\geq3$

$x _{2}+x_{3}\geq4$

Target is minimized $z=2x_{1}+5x_{2}+2x_{3}$

Hey, this isn't a linear plan, MA ' am, I'm not a simplex.

Well, we'll do it with the cost stream:

Suppose we used to have $inf$ volunteers, and then each day there were fewer volunteers and needed to spend money on recruiting. $inf$ volunteers are now required to be available every day.

Then, just follow the changed test instructions to build the map:

The source point to the first point is connected to the edge of $ (inf,0) $, and after each point backwards a point is connected to the edge of $ (inf-p[i],0) $, the $m+1$ point as a sink point

After each of the volunteers, we $s[i]$ from point $t[i]+1$ to the side of $ (inf,c[i]) $.

At this point the maximum flow must be $inf$ not , the minimum cost is the answer.

  What is the zkw cost flow ... It is said that the cost stream does not card EK algorithm

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 Constll INF =1e18;5 structEdge6 {7     intu, V, NXT;8 ll W, C;9}e[25005];Tenqueue<int>Q; One intN, Etot =1, fst[1005], fa[1005]; A BOOLinq[1005]; -ll ans, dis[1005]; -   the voidAddedge (intUintV, ll W, ll c) - { -E[++etot] = (edge) {u, V, Fst[u], W, c}, Fst[u] =Etot; -E[++etot] = (edge) {V, U, Fst[v],0,-C}, fst[v] =Etot; + } -   + BOOLSPFA () A { at     intu; -memset (DIS, the,sizeof(DIS)); -Dis[n +2] =0, Q.push (n +2), Inq[n +2] =true; -      while(!q.empty ()) -     { -U =Q.front (), Q.pop (); in          for(inti = Fst[u]; I i =e[i].nxt) -             if(E[I].W && DIS[E[I].V] > Dis[u] +e[i].c) to             { +DIS[E[I].V] = Dis[u] +e[i].c; -FA[E[I].V] =i; the                 if(!INQ[E[I].V]) *Q.push (E[I].V), inq[e[i].v] =true; $             }Panax NotoginsengInq[u] =false; -     } the     if(Dis[n +1] >= INF)return false; +     return true; A } the   + voidEdmond_karp () - { $ll w =INF; $      for(inti = Fa[n +1]; I i =fa[e[i].u]) -W =min (w, E[I].W); -      for(inti = Fa[n +1]; I i =fa[e[i].u]) theE[I].W-= W, e[i ^1].W + = W, ans + = e[i].c *W; - }Wuyi   the intMain () - { Wu     intm, u, v; - ll W; AboutCIN >> N >>m; $Addedge (n +2,1Inf0); -      for(inti =1; I <= N; ++i) -     { -CIN >>W; AAddedge (i, i +1, Inf-w,0); +     } the      for(inti =1; I <= m; ++i) -     { $cin >> u >> v >>W; theAddedge (U, v +1, INF, W); the     } the      while(SPFA ()) the Edmond_karp (); -cout << ans <<Endl; in     return 0; the}
View Code

[BZOJ1061] [Noi2008] Volunteer recruitment (fee flow)

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.