Codeforces 348 D - Turtles Lindström–Gessel–Viennot lemma

 

 

#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
 
const int N = 3e3 + 5;
const int MOD = 1e9 + 7;
int dp[N][N], n, m;
char s[N][N];
int solve(int a, int b, int c, int d) {
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) dp[i][j] = 0;
    for (int i = a; i <= c; ++i) {
        for (int j = b; j <= d; ++j) {
            if(i == a && j == b) {
                if(s[i][j] == '.') dp[i][j] = 1;
            }
            else {
                if(s[i][j] == '.') dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
            }
        } 
    } 
    return dp[c][d];
}
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%s", s[i]+1);
    printf("%lld\n", (solve(1, 2, n-1, m)*1LL*solve(2, 1, n, m-1) - solve(1, 2, n, m-1)*1LL*solve(2, 1, n-1, m)%MOD+MOD)%MOD);
    return 0;
}

 

posted @ 2019-10-31 20:07  Aragaki  阅读(179)  评论(0编辑  收藏  举报