Description
There were n boys and n Girls at a dance. At the beginning of each song, all the boys and girls fit into the N-dance ballroom. Every boy will not dance with the same girl for two (or more) dance songs. There are some boys and girls who like each other, while others dislike each other (not "one-way Likes"). Each boy is willing to dance with the K-not-like girls at most, and each girl is willing to dance with the K-not-liked boys at most. Given the information that every pair of boys and girls love each other, how many dances can a ball have?
Input
The first line consists of two integers n and K. The following n rows contain n characters per line, where the J character of Line I is ' Y ' when and only if boy I and girl J love each other.
Output
Only one number, that is, the maximum number of dances.
Sample Input3 0
YYY
YYY
YYY
Sample Output3HINT
N<=50 k<=30
Puzzle: The boys I split into two points i1,i2, will girl J also dismantled for j1,j2, if I and j like each other, then from I1 to J1 with a capacity of 1 side, otherwise from i2 to J2 with a capacity of 1 side for boys I, from I1 to i2 with a capacity of the side of K, for Girls J, by J2 to J1 a capacity of the side of the K and then the two-point Tim, from S to each boy i1 the side of the Tim, by each girl J1 to the side of the t even capacity Tim, and then if the maximum flow =tim*n, then this number of feasible code:
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 #defineMAXN 2507 #defineMAXM 60008 #defineINF 10611095679 using namespacestd;Ten Charch; One BOOLOK; A voidReadint&x) { - for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1; - for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ()); the if(OK) x=-x; - } - Charg[ -][ -]; - intn,k,l,r,m; + structflow{ - intS,T,TOT,NOW[MAXN],SON[MAXM],PRE[MAXM],VAL[MAXM]; + intDIS[MAXN],HEAD,TAIL,LIST[MAXN]; A BOOLBO[MAXN]; at voidInit () {s=0, t=1, tot=1, Memset (now,0,sizeof(now));} - voidPutintAintBintc) {pre[++tot]=now[a],now[a]=tot,son[tot]=b,val[tot]=C;} - voidAddintAintBintc) {put (a,b,c), put (B,a,0);} - BOOLBFs () { -Memset (Bo,0,sizeof(bo)); -Head=0, tail=1, list[1]=s,dis[s]=0, bo[s]=1; in while(head<tail) { - intu=list[++Head]; to for(intP=now[u],v=son[p];p; p=pre[p],v=Son[p]) + if(Val[p]&&!bo[v]) bo[v]=1, dis[v]=dis[u]+1, list[++tail]=v; - } the returnBo[t]; * } $ intDfsintUintrest) {Panax Notoginseng if(u==t)returnrest; - intans=0; the for(intP=NOW[U],V=SON[P];p &&rest;p=pre[p],v=Son[p]) + if(val[p]&&dis[v]==dis[u]+1){ A intD=Dfs (V,min (rest,val[p)); theval[p]-=d,val[p^1]+=d,ans+=d,rest-=D; + } - if(!ans) dis[u]=-1; $ returnans; $ } - intDinic () { - intans=0; the while(BFS ()) ans+=DFS (s,inf); - returnans;Wuyi } the }f,tmp; - BOOLCheckintLim) { Wuf=tmp; - for(intI=1; i<=n;i++) F.add (f.s,i<<1, Lim); About for(intI=1; i<=n;i++) F.add (i+n) <<1, F.t,lim); $ returnF.dinic () ==lim*N; - } - intMain () { - read (n), read (k), F.init (); A for(intI=1; i<=n;i++) scanf ("%s", g[i]+1); + for(intI=1; i<=n;i++) F.add (i<<1+ (n<<1)+1, k); the for(intI=1; i<=n;i++) F.add ((i+n) <<1)+1, (I+n) <<1, k); - for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) $ if(g[i][j]=='Y') F.add (i<<1, (J+n) <<1,1); the ElseF.add ((i<<1)+1, ((j+n) <<1)+1,1); the for(tmp=f,l=0, r=n,m= ((l+r) >>1)+1; l<r;m= (L+r) >>1)+1)if(check (m)) l=m;Elser=m-1; theprintf"%d\n", L); the return 0; -}
bzoj1305: [Cqoi2009]dance dancing