Bzoj 3550 Vacation

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=3550

Test instructions: There are 3N number, you need to select some number, first of all to ensure that any length is n the number of the selection of <=k, and secondly to ensure that the number of the most selected.

Ideas: And this question like http://www.cnblogs.com/qzqzgfy/p/5612261.html

It can be converted into an inequality and then the cost flow is obtained.

1#include <cstdio>2#include <cmath>3#include <iostream>4#include <algorithm>5#include <cstring>6 #defineINF 0x7fffffff7 inttot,go[200005],next[200005],first[200005],flow[200005],cost[200005];8 intdis[200005],vis[200005],op[200005],edge[200005], from[200005],ans,a[200005];9 intn,k,s,t,c[200005];Ten intRead () { One     intt=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; the } - voidInsertintXintYintZintl) { -tot++; -go[tot]=y; +next[tot]=First[x]; -first[x]=tot; +flow[tot]=Z; Acost[tot]=l; at } - voidAddintXintYintZintl) { -Insert (x,y,z,l); op[tot]=tot+1; -Insert (Y,x,0,-L); op[tot]=tot-1; - } - BOOLSPFA () { in     for(inti=s;i<=t;i++) dis[i]=0x3f3f3f3f, vis[i]=0; -    intH=1, t=1; vis[s]=1; c[1]=s;dis[s]=0; to     while(h<=t) { +        intnow=c[h++]; -         for(intI=first[now];i;i=Next[i]) { the              intPur=Go[i]; *              if(dis[pur]>dis[now]+cost[i]&&Flow[i]) { $dis[pur]=dis[now]+Cost[i];Panax Notoginseng                  from[pur]=Now ; -edge[pur]=i; the                 if(Vis[pur])Continue; +c[++t]=pur; Avis[pur]=1; the             } +         } -vis[now]=0; $     } $     returndis[t]!=0x3f3f3f3f; - } - voidUpdata () { the     intmn=0x7fffffff; -      for(intI=t;i!=s;i= from[i]) {Wuyimn=std::min (Mn,flow[edge[i]); the     } -      for(intI=t;i!=s;i= from[i]) { Wuflow[edge[i]]-=mn; -flow[op[edge[i]]]+=mn; Aboutans+=mn*Cost[edge[i]]; $     } - } - voidMncostflow () { -ans=0; A     while(SPFA ()) Updata (); +printf"%d\n",-ans); the } - intMain () { $N=read (); K=read (); s=0; t=2*n+3; the      for(intI=1; i<=3*n;i++) thea[i]=read (); the      for(intI=1; i<=2*n+1; i++) theAdd (i+1, I,inf,0); -Add1, T,k,0); inAdd (S,2*n+2K0); the      for(intI=1; i<=n;i++) theAdd (i+1,1,1,-a[i]); About      for(inti=n+1; i<=n+n;i++) theAdd (i+1, i+1-N,1,-a[i]); the      for(inti=n+n+1; i<=n*3; i++) theAdd2*n+2, i-n+1,1,-a[i]); + Mncostflow (); -}

Bzoj 3550 Vacation

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.