bzoj1061: [Noi2008] Volunteer recruitment

Source: Internet
Author: User

Orz

The https://www.byvoid.com/blog/noi-2008-employee/here.

Only for the time being understood

Since inequality cannot be poor, plus Yi becomes equation

After the difference, each x appears at most once, so that you can consider the impact of two (through the edge, where the outflow so much there will flow in so, corresponding to a positive and negative)

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <algorithm>5#include <iostream>6 7 using namespacestd;8 9 voidSetio (Const string&s) {TenFreopen ((S +". in"). C_STR (),"R", stdin); OneFreopen ((S +". out"). C_STR (),"W", stdout); A } -Template<typename q> Q Read (q&x) { -     Static Charc, F; the      for(f =0; c = GetChar (),!isdigit (c); )if(c = ='-') F =1; -      for(x =0; IsDigit (c); c = GetChar ()) x = x *Ten+ C-'0'; -     if(f) x =-x; -     returnx; + } -Template<typename q>Q Read () { +     StaticQ x; Read (x);returnx; A } at //MCMF -  - Const intN = ++Ten, M =25000+Ten, INF = ~0u>>1; -  - structEdge { -     intto, ADV, cost; inEdge *Next; -Edge (intto =0,intadv =0,intCost =0, Edge *next =0): To, ADV (ADV), cost, next (next) {} to}pool[m *2], *pis = Pool, *Fir[n]; +  - voidAddedge (intUintVintWintc) { theFir[u] =New(pis++) Edge (V, W, C, Fir[u]); *FIR[V] =New(pis++) Edge (U,0, -c, Fir[v]); $ }Panax Notoginseng  - #defineINV (p) (Pool + (((p)-pool) ^1) the  + namespaceMCMF { A     intN, S, T; the     intD[n], q[n], QL, QR, a[n]; +Edge *Pre[n]; -     BOOLInq[n]; $      $     BOOLInsertintUintDisint( ) { -         if(D[u] >dis) { -A[u] =; theD[u] =dis; -             if(!Inq[u]) {Wuyiq[qr++] =u; the                 if(QR = = N) QR =0; -Inq[u] =1; Wu             } -             return 1; About}return 0; $     } -      -     BOOLSPFA (int& Flow,int&Cost ) { -          for(intU =1; U <= N; u++) D[u] = INF, inq[u] =0; AInsert (S,0, INF); +          while(QL ^qr) { the             intU = q[ql++];if(QL = = N) QL =0; Inq[u] =0; -              for(Edge *p = fir[u]; p; p = p->next)if(p->adv) { $                 if(Insert (P->to, D[u] + p->cost, min (A[u], p->adv)))  { thePre[p->to] =p; the                 } the             } the         } -         if(D[t] = = INF)return 0; inFlow + =A[t]; theCost + = d[t] *A[t]; the          for(intu = t; U! = S; U = INV (Pre[u])To ) { AboutPRE[U]-&GT;ADV-=A[t]; theINV (Pre[u])->adv + =A[t]; the         } the         return 1; +     } -      the     intMainint_n,int_s,int_t) {Bayin = _n, s = _s, t =_t; the         intFlow =0, cost =0; the          while(SPFA (flow, cost)); -         returnCost ; -     } the } the  the Const intMAXN = ++Ten, MAXM =10000+Ten; the intDEMAND[MAXN]; -  the intMain () { the #ifdef DEBUG theFreopen ("In.txt","R", stdin);94Freopen ("OUT.txt","W", stdout); the #endif the      the     intn = read<int> (), M = read<int>();98     ints = n +2, T = s +1; About      for(inti =1; I <= N; i++) { - read (demand[i]);101Addedge (i +1, I, INF,0);102     }103      for(inti =1; I <= n +1; i++) {104         intDLT = Demand[i]-demand[i-1]; the         if(DLT >=0) Addedge (S, I, DLT,0);106         ElseAddedge (i, T,-DLT,0);107     }108     intL, R, C;109      for(inti =1; I <= m; i++) { the Read (l), read ( R), read (c);111Addedge (L, R +1, INF, c); the     }113      theprintf"%d\n", Mcmf::main (t, S, t)); the      the     return 0;117}
View Code

bzoj1061: [Noi2008] Volunteer recruitment

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.