"BZOJ1305" [Cqoi2009]dance Dance

Source: Internet
Author: User

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

The boys and girls are x,ys to X-side, the capacity of the a,y to the meeting point, the capacity of AA can be two points, can be enumerated (anyway, only 30) boys x-->y with the side for K, girls y-->x with the side for K, boys like girls in the left side, vice versa in the right
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5 using namespacestd;6 Const intinf=100000000, n=1005;7 structee{intTo,next,f;} e[500001];8 inthead[n],q[n*2],dis[n],map[n][n];9 intS,t,n,m,cnt=1, ans,w,k,mx;Ten     One voidInsintUintVintf) { Ae[++cnt].to=v;e[cnt].f=f;e[cnt].next=head[u];head[u]=CNT; -e[++cnt].to=u;e[cnt].f=0; e[cnt].next=head[v];head[v]=CNT; - } the     - BOOLBFs () { -      for(intI=1; i<=t;i++) dis[i]=inf; -     intH=0, t=1, now; +q[1]=s;dis[s]=0; -      while(h!=t) { +now=q[++h]; A          for(intI=head[now];i;i=E[i].next) { at             intv=e[i].to; -             if(e[i].f&&dis[now]+1<Dis[v]) { -dis[v]=dis[now]+1; -                 if(v==t)return 1; -q[++t]=v; -             } in         } -     } to     if(Dis[t]==inf)return 0;return 1; + } -     the intDinic (intNowintf) { *     if(now==t)returnF; $     intrest=F;Panax Notoginseng      for(intI=head[now];i;i=E[i].next) { -         intv=e[i].to; the         if(e[i].f&&dis[v]==dis[now]+1&&rest) { +             intt=dinic (V,min (REST,E[I].F)); A             if(!t) dis[v]=0; thee[i].f-=T; +e[i^1].f+=T; -rest-=T; $         } $     } -     returnF-rest; - } the voidBuildintf) { -Cnt=1;WuyiMemset (Head,0,sizeof(head)); the      for(intI=1; i<=n;i++) ins (s,i,f); -      for(inti=n+1; i<=2*n;i++) ins (i,t,f); Wu      for(intI=1; i<=n;i++) Ins (i,i+2*n,k); -      for(inti=n+1; i<=2*n;i++) Ins (i+2*n,i,k); About      for(intI=1; i<=n;i++) $          for(intj=1; j<=n;j++){ -             if(Map[i][j]) ins (i,j+n,1); -             ElseINS (i+2*n,j+3*n,1); -         }  A } + intMain () { thescanf"%d%d",&n,&k); -t=4*n+1; $     Chars[ -]; the      for(intI=1; i<=n;i++){ thescanf"%s", s+1); the          for(intj=1; j<=n;j++) the             if(s[j]=='Y') map[i][j]=1; -     } in     intL=0, r= -; the      while(l<=R) the     { About         intMid= (l+r) >>1; the build (mid); theans=0; while(BFS ()) ans+=dinic (s,inf); the         if(Ans>=n*mid) {mx=mid;l=mid+1;} +         Elser=mid-1; -     } theprintf"%d", MX);Bayi}

"BZOJ1305" [Cqoi2009]dance Dance

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.