Topic links
Test instructions: There are a lot of party held on the same day, with the start time and deadline for each of them, the women who love to play are mainly involved in as many of them as possible, and the number of party to be attended by the host is not less than half an hour.
1#include <stdio.h>2#include <string.h>3#include <queue>4 using namespacestd;5 #defineCaptype __int326 Const intN =4005;7 8 9 Captype Cap[n][n],f[n][n],rest[n];Ten intSnode,enode,pre[n]; One A - voidinit () { -Memset (F,0,sizeof(f)); thememset (Cap,0,sizeof(CAP)); - } - - + BOOLSearchPath (intN) {//find an augmented road - BOOLvist[n]={0}; +queue<int>Q; A intu,v; atU=snode; vist[u]=1; -Pre[u]=u; rest[u]=1<< -; - q.push (u); - while(!Q.empty ()) { -u=Q.front (); Q.pop (); - for(v=1; v<=n; v++) in if(!vist[v]&&cap[u][v]-f[u][v]>0) - { tovist[v]=1; pre[v]=u; + if(cap[u][v]-f[u][v]>Rest[u]) -rest[v]=Rest[u]; the Else *rest[v]=cap[u][v]-F[u][v]; $ if(V==enode)return true;Panax Notoginseng Q.push (v); - } the } + return false; A } theCaptype Maxflow (intSintTintN) { +Captype ans=0; -Snode=s; Enode=T; $ while(SearchPath (n)) { $ans+=Rest[enode]; - intv=Enode; - while(v!=SNode) { the intu=Pre[v]; -f[u][v]+=Rest[enode];WuyiF[v][u]-=rest[enode];//give a chance to return thev=u; - } Wu } - returnans; About } $ intMain () { -Freopen ("C:/users/fuliujun/desktop/input.txt","R", stdin); -Freopen ("C:/users/fuliujun/desktop/output.txt","W", stdout); - inta,b,m,n,a1[ -],b1[ -],n1,sum=0, day=1; A while(SCANF ("%d", &n)! =EOF) { + for(intI=0; i<n;i++){ thescanf"%d%d",&a1[i],&b1[i]); -sum+= (B1[i]-a1[i]) *2; $ } then1= the+N; them=sum+ ++N; the init (); the for(intI=0;i< +; i++) -cap[1][i+2]=1; in for(intI=0; i<n;i++) thecap[ the+i][n1]=1; the for(intI=0; i<n;i++){ About intJ= (B1[i]-a1[i]) *2; the for(intz=1; z<=j;z++) the{inttem=a1[i]*2- the; thecap[tem+z][ the+i]=1; + } - } the if(n!=0){Bayiprintf"On day %d Emma can attend as many as%d parties.\n", Day,maxflow (1, n1,n1)); the } theday++; - } - fclose (stdin); the fclose (stdout); the return 0; the}
View Code
Summer Training #10 Div.2 D (maximum binary matching)