The provincial team members (most) did not come ... Like my satay every day to write and write the metaphysical algorithm can be ranked on the top of the list ... It is true that the person who is writing the hang is far less than the person who is violent pat ... The continuation of the land will supplement some of the problems. (But some of them are too divine to be able to fill the puzzle.)
There are n items, two bags A and b. If the item I and j is placed in the same bag, then the cost is t[i][j], guarantee t[i][i]=0,t[i][j]=t[j][i].
The cost of a bag d= the maximum value of the 22 item cost in the bag. You need to assign the item to two bags and minimize D (A) +d (B).
2<=n<=250,0<=t[i][j]<=10^9.
Chen Xu there is a violent multiplication of the practice can run past ... Knees Rotten
We may wish to set D (a) <=d (b), then we enumerate D (b), and it is clear that the feasibility of sub-d (a) can be awarded.
For two items i,j, if D (A) <t[i][j]<=d (b), then I and J must have at least one in B. If T[i][j]>d (b), then I and J cannot be put together.
So this becomes a 2-sat problem that can be solved with the classic Tarjan approach.
This is O (N^4logn), because too much metaphysics can only get partial points.
The practice seems to be very good, how to optimize it?
We find that enum D (B) looks less plausible, does it really have to enumerate the O (n^2) values?
Obviously not, we're thinking of creating a maximum spanning tree, with T as the edge. Next consider the black-and-white coloring of the spanning tree, if a set B includes a point of two colors, then obviously D (b) is the edge on the largest spanning tree (which can be obtained by the correctness of the Kruskal algorithm). Otherwise b includes only one point of color, containing all white dots or just All black dots (why all points?). Because if it is part of the point, then a must include all the points of the other color. Because it is the largest spanning tree, then D (A) >d (B)). So we just have to try these d (B).
This seems to be O (N^3LOGN).
We can add some artifice to optimize, my practice is to divide the weight of two points, and then each time according to the optimal solution casually cut pruning, so it can be over.
#include <iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespacestd;#defineSZ 666intn,t[sz][sz],ls[sz*sz],ln=0, en=0;intFf[sz];intGfintx) { returnff[x]?ff[x]=GF (Ff[x]): x;}intm=0, fst[sz*sz*5],vb[sz*sz*5],nxt[sz*sz*5];voidAd_de (intAintb) {++m; nxt[m]=fst[a]; fst[a]=m; vb[m]=b;}voidAdde (intAintb) {Ad_de (A, b); Ad_de (b,a);}structEDG {intx, y;} es[sz*SZ];BOOL operator< (EDG A,edg b) {returnT[a.x][a.y]>t[b.x][b.y];}intds[sz*sz],dn=0;intCol[sz];voidDfsintXintc) { if(col[x]!=-1)return; COL[X]=C; for(intE=fst[x];e;e=nxt[e]) DFS (vb[e],!c);}//Tarjannamespacetj{intm=0, fst[sz*sz*5],nxt[sz*sz*5],vb[sz*sz*5];voidAd_de (intAintb) {++m; nxt[m]=fst[a]; fst[a]=m; vb[m]=b;}voidAdde (intAintb) {Ad_de (A, b); Ad_de (b,a);}intss[sz],sn=0, low[sz],dfn[sz],cnt=0, bl[sz],scc=0;BOOLIns[sz];voidinit () {M=sn=cnt=scc=0; for(intI=1; i<=2*n+1; i++) fst[i]=low[i]=dfn[i]=bl[i]=ins[i]=0;}voidTarjan (intx) {Low[x]=dfn[x]=++cnt; Ss[++sn]=x; ins[x]=1; for(intE=fst[x];e;e=Nxt[e]) { intb=Vb[e]; if(!dfn[b]) {Tarjan (b); low[x]=min (low[x],low[b]);} Else if(Ins[b]) low[x]=min (low[x],dfn[b]); } if(Dfn[x]!=low[x])return; intP ++SCC; Do{p=ss[sn--]; ins[p]=0; bl[p]=SCC; } while(p!=x);}}BOOLOkintDaintdb) {Tj::init (); for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) { intt=T[i][j]; if(t>db) {Tj::adde (i*2, j*2+1); Tj::adde (i*2+1, j*2); } Else if(t>da) {Tj::ad_de (i*2, j*2+1); Tj::ad_de (j*2, i*2+1); } } } for(intI=2; i<=2*n+1; i++) { if(!TJ::d fn[i]) Tj::tarjan (i); } for(intI=1; i<=n;i++)if(tj::bl[i*2]==tj::bl[i*2+1])return 0; return 1;}structF{f (stringT) {freopen (t+". in"). C_STR (),"R", stdin); Freopen (t+". out"). C_STR (),"W", stdout);}} __("Florida");intMain () {memset (col,-1,sizeof(col)); M=dn=ln=en=0; memset (FST,0,sizeof(FST)); memset (FF,0,sizeof(FF)); if(SCANF ("%d", &n) ==eof)return 0; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) scanf ("%d", &t[i][j]), t[j][i]=T[i][j]; } for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++)if(T[i][j]) ls[++ln]=T[i][j]; } sort (ls+1, ls+1+LN); Ln=unique (ls+1, ls+1+LN)-ls-1; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) Es[++en].x=i, es[en].y=J; } sort (es+1, es+1+en); for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) T[i][j]=lower_bound (ls,ls+1+LN,T[I][J])-ls; } for(intI=1; i<=en;i++) { intGA=GF (es[i].x), gb=GF (ES[I].Y); if(GA==GB)Continue; FF[GA]=GB; ds[++dn]=T[ES[I].X][ES[I].Y]; Adde (ES[I].X,ES[I].Y); } DFS (1,0); intmaxn[2]={0,0}; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) { if(Col[i]==col[j]) maxn[col[i]]=Max (maxn[col[i]],t[i][j]); }} ds[++dn]=maxn[0]; ds[++dn]=maxn[1]; Sort (ds+1, ds+1+DN); Dn=unique (ds+1, ds+1+DN)-ds-1; intans=2000000033; for(intI=0; i<=dn;i++) { intdb=ds[i],qaq=DB; while(qaq>=0&&ls[db]+ls[qaq]>=ans)--Qaq; if(qaq<0||! Ok (qaq,db))Continue; intL=0, r=Qaq; while(l!=r) {intMid= (l+r) >>1; if(OK (mid,db)) R=mid;ElseL=mid+1; } ans=min (ans,ls[db]+Ls[l]); } printf ("%d\n", ans); Main ();}
Fjoi Provincial Team Training Florida