
計數 DP
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
const int maxn = 1005;
const int mod = 1e9+7;
int n,dp[maxn][maxn];
char maze[maxn][maxn];
//
signed main(){
fastio;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>maze[i][j];
}
}
if(maze[1][1] == '*') return cout<<0<<"\n", 0;
dp[1][1] = 1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == 1 && j == 1) continue;
if(maze[i][j] == '*') continue;
dp[i][j] = dp[i-1][j] + dp[i][j-1];
dp[i][j] %= mod;
}
}
cout<<dp[n][n]<<"\n";
return 0;
}

發佈留言