标签:cep 二分 cli field input needed esc code href
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13386 | Accepted: 4923 |
Description
Input
Output
Sample Input
4 4 *.*. .*** ***. ..*.
Sample Output
4
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 55; char mp[maxn][maxn]; bool vis[maxn*maxn],G[maxn*maxn][maxn*maxn]; int id1[maxn][maxn],id2[maxn][maxn],tt1,tt2,g[maxn*maxn],n,m,tt; bool dfs(int u){ for(int v=1;v<=tt;v++){ if(!G[u][v]) continue; if(!vis[v]){ vis[v]=1; if(!g[v]||dfs(g[v])){ g[v]=u; return 1; } } } return 0; } void debug(){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) printf("%c ",mp[i][j]); puts(""); } } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",mp[i]+1); // debug(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(mp[i][j]!=‘*‘) continue; if(!id1[i-1][j]) id1[i][j]=++tt1; else id1[i][j]=id1[i-1][j]; if(!id2[i][j-1]) id2[i][j]=++tt2; else id2[i][j]=id2[i][j-1]; } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(mp[i][j]==‘*‘) G[id1[i][j]][id2[i][j]]=1; } int ans=0; tt=max(tt1,tt2); for(int i=1;i<=tt;i++){ memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } printf("%d\n",ans); return 0; }
标签:cep 二分 cli field input needed esc code href
原文地址:https://www.cnblogs.com/plysc/p/11442552.html