EC-final赛前一周

为信仰充值,与神犇赛码!年度最终决战,剑不出鞘更待何时?下周末双日,12.12~13,2015 ACM/ICPC EC-final 上海大学站,蓄势待发!全力备战

wpid-screenshot_2015-12-05-21-55-28.png wpid-230c7f4a3a36cc1f.jpg wpid-351324c2c7cdabb1.jpg wpid-screenshot_2015-12-05-21-55-05.png

wpid-screenshot_2015-12-05-22-02-33.png wpid-img_20151205_220342.jpg

ACM-ICPC Live Archive Regionals 2014 >> Asia - Kuala Lumpur 6811 - Irrigation Lines

参见:转载前页面

怎么读题时就没发现“每行每列各有一个水阀”?这是把问题转化成二分图模型的关键啊

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const int MAXN = 110;
char graph[MAXN][MAXN];
bool visited[MAXN];
int nCase, cCase, use[MAXN], m, n;

void init() {
memset(use, -1, sizeof(use));
}

void input() {
scanf("%d%d", &m, &n);
for (int i = 0; i < m; i++) {
scanf("%s", graph[i]);
}
}

bool find(int x) {
for (int j = 0; j < n; j++) {
if (graph[x][j] == '1' && !visited[j]) {
visited[j] = true;

if (use[j] == -1 || find(use[j])) {
use[j] = x;
return true;
}
}
}
return false;
}

int match() {
int count = 0;
for (int i = 0; i < m; i++) {
memset(visited, false, sizeof(visited));
if (find(i)) count++;
}
return count;
}

void solve() {
printf("Case #%d: %d\n", ++cCase, match());
}

int main() {
scanf("%d", &nCase);
while (nCase--) {
init();
input();
solve();

}
return 0;
}