Link to this code:
https://cses.fi/paste/7998916af42956188973b6/#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int INF = 1e9;
const ll LINF = 1e18;
const int N = 1e3 + 5;
const int MOD = 1e9 + 7;
int n;
string grid[N];
bool inSide(int x, int y) {
return (1 <= x && x <= n && 1 <= y && y <= n);
}
int memo[N][N];
int dp(int x, int y) {
if (!inSide(x, y)) return 0;
if (grid[x][y] == '*') return 0;
if (x == 1 && y == 1) return (grid[1][1] == '.');
int& ans = memo[x][y];
if (ans != -1) return ans;
ans = dp(x - 1, y) + dp(x, y - 1);
ans %= MOD;
return ans;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> grid[i];
grid[i] = ' ' + grid[i];
}
memset(memo, -1, sizeof memo);
cout << dp(n, n) << '\n';
}