Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
987 B
1
Indexable
Never
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;
int n;
char mat[1005][1005];
int memo[1005][1005];
int f(int i, int j) {
    if(i == n - 1 and j == n - 1) {
        return 1; // sme nasle 1 pat
    }
    if(memo[i][j] != -1) {
        return memo[i][j];
    }
    int ways = 0;
    if(j + 1 < n and mat[i][j + 1] != '*') {
        ways += f(i, j + 1);
        ways %= MOD;
    }
    if(i + 1 < n and mat[i + 1][j] != '*') {
        ways += f(i + 1, j);
        ways %= MOD;
    }
    memo[i][j] = ways;
    return memo[i][j];
}
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> mat[i][j];
            memo[i][j] = -1;
        }
    }
    if(mat[0][0] == '*') {
        cout << 0 << endl;
    }
    else
        cout << f(0, 0) << endl;
    return 0;
}
/*
 
 f(i, j) --> f(i, j + 1); f(i + 1, j)
 i == n - 1 && j == n - 1
 return 1;
 ....
 .*..
 ...*
 *...

 **/