## 1305: [CQOI2009]dance跳舞

Time Limit: 5 Sec  Memory Limit: 162 MB
Submit: 2660  Solved: 1101
[Submit][Status][Discuss]

3 0
YYY
YYY
YYY

3

N<=50 K<=30

## Source

[Submit][Status][Discuss]

Ai:这个男生or女生和互相喜欢的男生or女生跳舞~
Bi:这个男生or女生和*********的男生or女生跳舞-_-

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int INF = ~0U>>1;
const int maxn = 1E5 + 10;

struct E{
int to,cap,flow;
E(){}
E(int to,int cap,int flow): to(to),cap(cap),flow(flow){}
}edgs[maxn];

int n,cnt,tot,Cnt,s,t,k,vis[maxn],L[maxn],cur[maxn],A[110],B[110],C[110];
char cp[55][55];

vector <int> v[maxn];
queue <int> Q;

{
v[x].push_back(cnt);
edgs[cnt++] = E(y,w,0);
v[y].push_back(cnt);
edgs[cnt++] = E(x,0,0);
}

bool BFS()
{
vis[s] = ++Cnt;
L[s] = 1;
Q.push(s);
while (!Q.empty()) {
int k = Q.front(); Q.pop();
for (int i = 0; i < v[k].size(); i++) {
E e = edgs[v[k][i]];
if (e.cap == e.flow) continue;
if (vis[e.to] == Cnt) continue;
L[e.to] = L[k] + 1;
vis[e.to] = Cnt;
Q.push(e.to);
}
}
return vis[t] == Cnt;
}

int Dicnic(int x,int a)
{
if (x == t || !a) return a;
int flow = 0;
for (int &i = cur[x]; i < v[x].size(); i++) {
E &e = edgs[v[x][i]];
if (e.cap == e.flow) continue;
if (L[e.to] != L[x] + 1) continue;
int f = Dicnic(e.to,min(a,e.cap - e.flow));
if (!f) continue;
e.flow += f;
a -= f;
flow += f;
edgs[v[x][i]^1].flow -= f;
if (!a) return flow;
}
if (!flow) L[x] = -1;
return flow;
}

bool Judge(int now)
{
cnt = 0;
for (int i = 1; i <= n; i++)
for (int i = n + 1; i <= 2*n; i++)
for (int i = 1; i <= n; i++) {
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (cp[i][j] == 'Y')
else
int MaxFlow = 0;
while (BFS()) {
for (int i = s; i <= t; i++) cur[i] = 0;
MaxFlow += Dicnic(s,INF);
}
for (int i = s; i <= t; i++)
v[i].clear();
return MaxFlow == n*now;
}

int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif

cin >> n >> k;
t = 6*n + 1;
for (int i = 1; i <= n; i++)
scanf("%s",cp[i] + 1);
for (int i = 1; i <= 2*n; i++) {
A[i] = ++tot;
B[i] = ++tot;
C[i] = ++tot;
}

int l = 0,r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (Judge(mid)) l = mid;
else r = mid;
}
if (Judge(r)) cout << r;
else cout << l;
return 0;
}


#### 【bzoj1305】[CQOI2009]dance跳舞 最大流

2016-03-10 21:12:58

#### 【CQOI2009】跳舞

2014-03-16 20:55:42

#### BZOJ 1305 [CQOI2009] dance跳舞

2017-01-04 19:15:16

#### BZOJ 1305 [CQOI2009]dance跳舞

2016-05-18 17:48:04

#### BZOJ 1305: [CQOI2009]dance跳舞

2014-03-15 18:49:41

#### 【bzoj 1305】[CQOI2009]dance跳舞

2017-04-15 09:22:34

#### 【BZOJ 1305】 [CQOI2009]dance跳舞

2015-03-01 23:28:54

#### 谁说大象不能跳舞(英文原版Who Says Elephants Can't Dance)

2009年11月21日 1.03MB 下载

#### bzoj 1305: [CQOI2009]dance跳舞（二分+最大流）

2016-05-05 09:30:32

#### BZOJ 1305: [CQOI2009]dance跳舞 最大流

2017-05-26 11:23:50

## 不良信息举报

1305: [CQOI2009]dance跳舞