首页 > 其他 > 详细

Codeforces 348D DP + LGV定理

时间:2019-06-10 09:51:49      阅读:115      评论:0      收藏:0      [点我收藏+]

题意及思路: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);
} 

  

Codeforces 348D DP + LGV定理

原文:https://www.cnblogs.com/pkgunboat/p/10996073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!