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);
} 

  

上一篇:ABAP EXCEPTION


下一篇:Linux CPU负载状态:%us/%sy/%ni/%id/%wa/%hi/%si/%st含义