标签:max names may pat include ons oar boa put
【原题】
Description
Input
Output
Sample Input
4 4 *.*. .*** ***. ..*.
Sample Output
4
Hint
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <list> #include <map> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <iomanip> #define LL long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f #define PI 3.1415926535898 #define F first #define S second #define lson rt << 1 #define rson rt << 1 | 1 using namespace std; const int maxn = 57; const int maxm = 2e5 + 7; int n, m; char mp[maxn][maxn]; int r[maxn][maxn], c[maxn][maxn]; int cnt = 0, rnum; vector <int> G[6000]; int vis[2 * maxn * maxn], link[2 * maxn * maxn]; bool dfs(int u) { for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (!vis[v]) { vis[v] = 1; if (!link[v] || dfs(link[v])) { link[v] = u; return true; } } } return false; } int max_match() { memset(link, 0, sizeof(link)); int ans = 0; for (int i = 1; i <= rnum; i++) { memset(vis, 0, sizeof(vis)); if (dfs(i)) ans++; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mp[i][j]; if (mp[i][j] == ‘*‘) { if (mp[i - 1][j] == ‘*‘) r[i][j] = r[i - 1][j]; else r[i][j] = ++cnt; } } } rnum = cnt; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (mp[i][j] == ‘*‘) { if (mp[i][j - 1] == ‘*‘) c[i][j] = c[i][j - 1]; else c[i][j] = ++cnt; G[r[i][j]].push_back(c[i][j]); } } } cout << max_match() << endl; }
标签:max names may pat include ons oar boa put
原文地址:https://www.cnblogs.com/hfcdyp/p/13374018.html