Codeforces 348D DP + LGV定理
题意及思路:https://www.cnblogs.com/chaoswr/p/9460378.html
代码:
#include <bits/stdc++.h> #define LL long long using namespace std; const int maxn = 3010; const LL mod = 1000000007; LL dp[maxn][maxn]; char s[maxn][maxn]; int n, m; LL ans[4]; void solve(int sx, int sy, LL ans[]) { if(s[sx][sy] == '#') return; memset(dp, 0, sizeof(dp)); dp[sx][sy] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if(s[i][j] == '#') continue; if(s[i + 1][j] != '#' && i < n) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; if(s[i][j + 1] != '#' && j < m) dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod; } ans[0] = dp[n - 1][m], ans[1] = dp[n][m - 1]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); solve(1, 2, ans); solve(2, 1, &ans[2]); printf("%lld\n", (ans[0] * ans[3] % mod - ans[1] * ans[2] % mod + mod) % mod); }