啦啦啦~~
解法:横向,竖向连续木板的为左右集合,原图表示两个集合的连接(这方法,绝了)
选择最少的顶点使所有顶点都被选择。--最小点覆盖
二分图最小点覆盖,最小顶点覆盖问题等价于最大匹配问题。
poj 好坑啊,一直听说数据往往超范围,今天终于见识到了,题意50*50,结果开了1000*1000....这么坑,好么?
/*
----------------------------------
Love is more than a word.
It says so much.
When I see these four letters,
I almost feel your touch.
This is only happened since
I fell in love with you.
Why this word does this,
I haven't got a clue.
To My Goddess
CY
----------------------------------
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 1000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define clehead(a) rep(i,maxn)a[i]=-1
/*
The time of story :
** while(1)
{
once upon a time,
there was a mountain,
on top of which there was a temple,
in which there was an old monk and a little monk.
Old monk was telling stories inside the temple.
What was he talking about?
** }
ÎûÎû
(*^__^*)
*/
#define sci(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define pri(a) printf("%d",a)
#define prie(a) printf("%d\n",a)
#define prd(a) printf("%lf",a)
#define prde(a) printf("%lf\n",a)
#define pre printf("\n")
#define LL(x) x<<1
#define RR(x) x<<|1
#define pb push_back
#define mod 90001
#define PI 3.141592657
const ull INF = 1LL << 61;
const int inf = int(1e5)+10;
const double eps=1e-5;
using namespace std;
struct node
{
int u,v,w;
int next;
};
bool cmp(int a,int b){
return a>b;
}
char str[maxn][maxn];
int n,m;
bool bmap[maxn][maxn];
bool bmark[10000];
int nx,ny;
int cx[10000];
int cy[10000];
int findpath(int u)
{
int i,j,k;
rep(i,ny){
if(bmap[u][i]&&!bmark[i]){
bmark[i]=1;
if(cy[i]==-1||findpath(cy[i]))
{
cy[i]=u;
cx[u]=i;
return 1;
}
}
}
return 0;
}
int maxmatch()
{
int i,j,k;
int res(0);
rep(i,nx)cx[i]=-1;
rep(j,ny)cy[j]=-1;
rep(i,nx){
if(cx[i]==-1){
rep(j,ny)bmark[j]=0;
res+=findpath(i);
}
}
return res;
}
int u[maxn][maxn];
int v[maxn][maxn];
void makestr()
{
int i,j,k;
cle(bmap);
int ip=0;
cle(u),cle(v);
rep(i,n)
{
rep(j,m)
{
if(str[i][j]=='*'){
ip++;
while(j<m&&str[i][j]=='*'){
u[i][j]=ip;
j++;
}
}
}
}
nx=ip;
ip=0;
rep(i,m){
rep(j,n)
{
if(str[j][i]=='*'){
ip++;
while(j<n&&str[j][i]=='*')
{
v[j][i]=ip;
j++;
}
}
}
}
rep(i,n)rep(j,m)if(str[i][j]=='*')
{
bmap[u[i][j]-1][v[i][j]-1]=true;
}
ny=ip;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>n>>m)
{
int i,j,k;
nx=0,ny=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>str[i][j];
}
}
makestr();
cout<<maxmatch()<<endl;
}
return 0;
}