Advertisement
LEGEND2004

Grid Paths

Aug 24th, 2023 (edited)
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int N = 1e3 + 5;
  6. const int mod = 1e9 + 7;
  7. int dp[N][N];
  8. char a[N][N];
  9.  
  10. signed main()
  11. {
  12.     int n;
  13.     cin >> n;
  14.     for(int i = 1; i <= n; i++){
  15.         for(int j = 1; j <= n; j++){
  16.             cin >> a[i][j];
  17.         }
  18.     }
  19.  
  20.  
  21.     for(int i = 1; i <= n; i++){
  22.         for(int j = 1; j <= n; j++){
  23.             if(a[i][j] == '*')
  24.                 continue;
  25.             if((i == 1) && (j == 1)){
  26.                 dp[i][j] = 1;
  27.                 continue;
  28.             }
  29.             dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
  30.             dp[i][j] %= mod;
  31.         }
  32.     }
  33.     cout << dp[n][n] << endl;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement