http://acm.hdu.edu.cn/showproblem.php?pid=1045
#include <iostream>
#include <cstring>
using namespace std;
const int maxx=102;
int cy[maxx];
int sy[maxx];
char gra[maxx][maxx];
int ex[maxx][maxx];int ey[maxx][maxx];
int g[maxx][maxx];
int ans,n,xn,yn;
int path(int u)
{
for(int v=1; v<=yn; v++)
if(g[u][v]>0&&!sy[v])
{
sy[v]=1;
if(!cy[v]||path(cy[v]))
{
cy[v]=u;
return 1;
}
}
return 0;
}
void MaxMatch()
{
ans=0;
memset(cx,0,sizeof(cx));memset(cy,0,sizeof(cy));
for(int i = 1; i<=xn; i++)
{
memset(sy,0,sizeof(sy));
ans+=path(i);
}
}
int main()
{
while(cin>>n&&n)
{
memset(ex,0,sizeof(ex));memset(ey,0,sizeof(ey));
memset(g,0,sizeof(g));
for(int i = 1; i<=n; i++)
for(int j =1; j<=n; j++)
cin>>gra[i][j];
int count=0;
for(int i = 1; i<=n; i++)
{
int flag=0;
for(int j = 1; j<=n; j++)
{
if(gra[i][j]=='.')
{
if(flag==0) count++;
ex[i][j]=count;
flag=1;
}
else if(gra[i][j]=='X') flag=0;
}
}
xn=count;
count=0;
for(int j = 1; j<=n; j++)
{
int flag=0;
for(int i = 1; i<=n; i++)
{
if(gra[i][j]=='.')
{
if(!flag) count++;
ey[i][j]=count;
flag=1;
}
else if(gra[i][j]=='X') flag=0;
}
}
yn=count;
for(int i = 1; i<=n; i++)
for(int j = 1; j<=n; j++)
if(ex[i][j]) g[ex[i][j]][ey[i][j]]=1;
MaxMatch();
cout<<ans<<endl;
}
}