HDU 5772 String problem

Source: Internet
Author: User

The most powerful closed sub-graph. The building is ingenious.

Most powerful closed sub-graphs:

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0;  while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intMAXN =30000+Ten;Const intINF =0x7FFFFFFF;structedge{int  from, to, cap, flow; Edge (intUintVintCintf): from(U), to (v), Cap (c), Flow (f) {}};vector<Edge>Edges;vector<int>G[MAXN];BOOLVIS[MAXN];intD[MAXN];intCUR[MAXN];intN, m, S, T;voidinit () { for(inti =0; i < MAXN; i++) g[i].clear (); Edges.clear ();}voidAddedge (int  from,intTo,intcap) {Edges.push_back (Edge ( from, to, Cap,0)); Edges.push_back (Edge to, from,0,0)); intW =edges.size (); g[ from].push_back (W-2); G[to].push_back (W-1);}BOOLBFS () {memset (Vis,0,sizeof(VIS)); Queue<int>p;    Q.push (s); D[s]=0; Vis[s]=1;  while(!Q.empty ()) {        intx =Q.front ();        Q.pop ();  for(inti =0; I<g[x].size (); i++) {Edge e=Edges[g[x][i]]; if(!vis[e.to] && e.cap>e.flow) {vis[e.to]=1; D[e.to]= D[x] +1;            Q.push (e.to); }        }    }    returnvis[t];}intDFS (intXinta) {    if(x = = T | | a = =0)        returnA; intFlow =0, F;  for(int&i = Cur[x]; I<g[x].size (); i++) {Edge e=Edges[g[x][i]]; if(d[x]+1= = d[e.to]&& (F=dfs (E.to,min (a,e.cap-e.flow)) >0) {Edges[g[x][i]].flow+=F; Edges[g[x][i]^1].flow-=F; Flow+=F; A-=F; if(a==0) Break; }    }    if(!flow) d[x] =-1; returnflow;}intDinic (intSintt) {    intFlow =0;  while(BFS ()) {memset (cur,0,sizeof(cur)); Flow+=DFS (S, INF); }    returnflow;}Const intmaxm= the;intt,len,a[maxm],b[maxm],w[maxm][maxm],val[2*maxm*Maxm],ans;CharSTR[MAXM];intMain () {scanf ("%d", &t);intcas=1;  while(t--) {scanf ("%d", &len); scanf"%s", str);  for(intI=0;i<Ten; i++) scanf ("%d%d",&a[i],&B[i]);  for(intI=0; i<len;i++) for(intj=0; j<len;j++) scanf ("%d",&W[i][j]); Init (); Ans=0; S=len*len+len+Ten; val[s]=0; T=len*len+len+Ten+1; val[t]=0;  for(intI=0; i<len;i++) for(intj=i+1; j<len;j++) {Val[i*len+j]=w[i][j]+W[j][i]; Addedge (i*len+j,len*len+I,inf); Addedge (i*len+j,len*len+J,inf); if(val[i*len+j]>0) Addedge (S,i*len+j,val[i*len+j]), ans=ans+val[i*len+J]; Else if(val[i*len+j]<0) Addedge (i*len+j,t,-val[i*len+J]); }         for(inti=len*len;i<=len*len+len-1; i++) {Val[i]=-a[str[i-len*len]-'0']; Addedge (I,len*len+len+str[i-len*len]-'0', INF); if(val[i]>0) Addedge (S,i,val[i]), ans=ans+Val[i]; Else if(val[i]<0) Addedge (i,t,-Val[i]); }         for(inti=len*len+len;i<=len*len+len+Ten-1; i++) {Val[i]=-b[i-(Len*len+len)]+a[i-(len*len+Len)]; if(val[i]>0) Addedge (S,i,val[i]), ans=ans+Val[i]; Else if(val[i]<0) Addedge (i,t,-Val[i]); } ans=ans-dinic (s,t); printf ("Case #%d:%d\n", cas++, ans); }    return 0;}

HDU 5772 String problem

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.