题意:在二维平面内,求从左上角走到右下角的两条不相交路线的方案数
思路:Lindström–Gessel–Viennot
.
其中e(a, b)表示a 到 b的路径条数。所以答案是
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[20];
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
char s[3005][3005];
ll dp[3005][3005];
ll solve(int x,int y,int xx,int yy)
{
if(s[x][y]=='#')
return 0;
memset(dp,0,sizeof(dp));
dp[x][y]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(s[i][j]=='#')
continue;
dp[i][j]+=dp[i-1][j]+dp[i][j-1];
dp[i][j]%=mod;
}
}
return dp[xx][yy];
}
int main()
{
//test;
n=read(),m=read();
for(int i=1;i<=n;i++)
scanf("%s",s[i]+1);
ll tmp=solve(1,2,n-1,m)*solve(2,1,n,m-1)-solve(1,2,n,m-1)*solve(2,1,n-1,m);
printf("%d\n",(tmp%mod+mod)%mod);
}