codeforces 348D Turtles
题意
题解
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---
const int N = 3030, P = 1e9+7;
int n, m;
int dp[2][N][N];
string s[N];
inline int add(int x, int y) {
int res = x + y;
if(res >= P) res -= P;
return res;
}
inline int mul(int x, int y) {
return 1ll * x * y % P;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n >> m;
rep(i, 1, n+1) {
cin >> s[i];
s[i] = " " + s[i];
}
dp[0][1][2] = (s[1][2] == '.');
dp[1][2][1] = (s[2][1] == '.');
rep(i, 1, n+1) rep(j, 1, m+1) if(s[i][j] == '.') {
rep(t, 0, 2) dp[t][i][j] = add(dp[t][i][j], add(dp[t][i-1][j], dp[t][i][j-1]));
}
int ans = mul(dp[0][n-1][m], dp[1][n][m-1]);
int res = mul(dp[0][n][m-1], dp[1][n-1][m]);
ans = add(ans, P - res);
cout << ans << endl;
return 0;
}