行列式再回顾!手机上图片
/**************************************************************
Problem: 4031
User: zhhx
Language: C++
Result: Accepted
Time:20 ms
Memory:1048 kb
****************************************************************/
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100005;
const ll mod=1e9;
int n,m;
int cnt;
int a[120][120],b[120][120];ll c[120][120];int id[12][12];
char ch[12][12];
ll gauss()
{
int mark=0;
for (int i=1;i<=cnt;i++)
{
int j=i;
for (;j<=cnt;j++) if (c[j][i]) break;
if (j==cnt+1) return 0;
if (j!=i)
{
swap(c[i],c[j]);
mark^=1;
}
for (int j=i+1;j<=cnt;j++)
{
while (c[j][i])
{
ll tmp=c[j][i]/c[i][i];
for (int l=i;l<=cnt;l++) c[j][l]=((c[j][l]-c[i][l]*tmp%mod)%mod+mod)%mod;
if (c[j][i]==0) break;
swap(c[i],c[j]);
mark^=1;
}
}
}
ll ans=1;
for (int i=1;i<=cnt;i++) ans=ans*c[i][i]%mod;
if (mark) ans=(mod-ans)%mod;
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) scanf("%s",ch[i]+1);
int u,v;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if (ch[i][j]=='.')
{
u=id[i][j]=++cnt;
if (v=id[i][j-1])
{
a[v][v]++,a[u][u]++;
b[u][v]++,b[v][u]++;
}
if (v=id[i-1][j])
{
a[v][v]++,a[u][u]++;
b[u][v]++,b[v][u]++;
}
}
for (int i=1;i<=cnt;i++)
for (int j=1;j<=cnt;j++) c[i][j]=((a[i][j]-b[i][j])%mod+mod)%mod;
cnt--;
printf("%lld",gauss());
return 0;
}