"Bzoj" "1221" "HNOI2001" software development

Source: Internet
Author: User

Network flow/Charge flow

That's the same as the napkin plan ... But I didn't do it ... so sad

Binary diagram modeling is very good to think, but to control the flow with the use of the same number of towels ... oh my God

In fact for every day we are to consume n[i] towel, then we can directly connect the edge i->t capacity of n[i], the cost is 0.

So just think about this n[i] where did the towel come from? = =:1. Bought 2. Quick wash 3. Slow Wash. It must have come from I-a-1 that day. So we even s->i capacity n[i] ...

Tat feels so wrong ...

...... Well...... Well...... So the result is: if the towel will be washed from S to I-a (b)-1 that day of the X node, and then flow to the first day of the Y node, anyway, a bit like the star race that problem, separate processing! Equal to the daily consideration alone? The towel source

1 /**************************************************************2 problem:12213 User:tunix4 language:c++5 result:accepted6 time:1396 Ms7 memory:5988 KB8 ****************************************************************/9  Ten //Bzoj 1221 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at     intv=0, sign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } - Const intn=2100, m=200000, inf=~0u>>2; intypedefLong LongLL; - /******************tamplate*********************/ to intN,f,a,b,fa,fb,ans; + structedge{int  from, To,v,c;}; - structnet{ the Edge E[m]; *     inthead[n],next[m],cnt; $     voidInsintXintYintZintc) {Panax Notoginsenge[++cnt]=(Edge) {x,y,z,c}; -NEXT[CNT]=HEAD[X]; head[x]=CNT; the     } +     voidAddintXintYintZintc) { AIns (x,y,z,c); Ins (y,x,0,-c); the     } +     int  from[n],q[m],d[n],s,t,ed; -     BOOLinq[n],sign; $     BOOLSPFA () { $         intL=0, r=-1; -F (I,1, T) d[i]=INF; -d[s]=0; Q[++r]=s; inq[s]=1; the          while(l<=R) { -             intx=q[l++];Wuyiinq[x]=0; the              for(intI=head[x];i;i=Next[i]) -                 if(e[i].v>0&& d[x]+e[i].c<D[e[i].to]) { Wud[e[i].to]=d[x]+e[i].c; -                      from[e[i].to]=i; About                     if(!Inq[e[i].to]) { $q[++r]=e[i].to; -inq[e[i].to]=1; -                     } -                 } A         } +         returnd[t]!=INF; the     } -     voidmcf () { $         intx=INF; the          for(intI= from[t];i;i= from[E[i]. from]) thex=min (x,e[i].v); the          for(intI= from[t];i;i= from[E[i]. from]){ thee[i].v-=x; -e[i^1].v+=x; in         } theans+=x*D[t]; the     } About     voidinit () { theN=getint (); A=getint (); b=getint (); theF=getint (); Fa=getint (); fb=getint (); theCnt=1; s=0; t=n+n+1; +         intx; -F (I,1, N) { thex=getint ();BayiAdd (s,i+n,inf,f); theAdd (S,i,x,0); Add (I+n,t,x,0); the             if(i<n) Add (i,i+1Inf0); -             if(i+a+1<=n) Add (i,i+n+a+1, INF,FA); -             if(i+b+1<=n) Add (i,i+n+b+1, INF,FB); the         } the          while(SPFA ()) MCF (); theprintf"%d\n", ans); the     } - }g1; the   the intMain () { the #ifndef Online_judge94Freopen ("1221.in","R", stdin); theFreopen ("1221.out","W", stdout); the #endif the g1.init ();98     return 0; About}
View Code

"Bzoj" "1221" "HNOI2001" software development

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.