CSES - Shared codeLink to this code:
https://cses.fi/paste/c073fab0ca7da99b1a0210/
#include<bits/stdc++.h>
#define mod 10000000007
using namespace std;
void solve();
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
int t=1;
/*is Single Test case?*///cin>>t;
while(t--)
{
solve();
cout<<"\n";
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}
void solve()
{
int n; cin>>n;
char a[n+1][n+1];
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
cin>>a[i][j];
}
}
// vector< vector<int> > dp(n+1, vector<int> (n+1, 0)); //initialising a 2d vector with all elements to 0
int dp[n+1][n+1];
for (int i = 1; i <= n+1; ++i)
{
for (int j = 1; j <= n+1; ++j)
{
dp[i][j] = 0;
}
}
if(a[n][n]!='*')
dp[n][n] = 1;
for (int i = n; i != 0; i--)
{
for (int j = n; j != 0; j--)
{
if(a[i][j] == '*'){
dp[i][j] = 0;
}
else{
if(i == n and j == n)
continue;
dp[i][j] += (dp[i+1][j])%mod + (dp[i][j+1])%mod;
//cout<<dp[i][j]<<" ";
}
}
}
cout<<dp[1][1];
}