Advertisement
Ahmed_Negm

Untitled

Nov 30th, 2022
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define nl '\n'
  9. #define sz(x) (ll)(x.size())
  10. #define all(x) x.begin(),x.end()
  11. #define rall(s)  s.rbegin(), s.rend()
  12. #define getline(s) getline(cin>>ws,s)
  13. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define pi  3.141592653589793
  15. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  17.  
  18.  
  19. void Fast_IO(){
  20. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. // freopen("filename.in", "r", stdin);
  22. // freopen("filename.txt", "w", stdout);
  23. #ifndef ONLINE_JUDGE
  24. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27.  
  28. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  29. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  30.  
  31. ll n;
  32. vector<vector<char>>grid;
  33. vector<vector<ll>>dp;
  34.  
  35. bool valid(ll i, ll j){
  36.     return i < n and j<n and grid[i][j] != '*';
  37. }
  38.  
  39. const ll mod = 1e9+7;
  40.  
  41. ll rec(ll i, ll j){
  42.     if(!valid(i,j)) return 0;
  43.     if(i == n-1 and j == n-1) return 1;
  44.     if(dp[i][j] != -1) return dp[i][j];
  45.     ll ans = 0;
  46.     ans = (ans + rec(i+1,j))%mod;
  47.     ans = (ans + rec(i,j+1))%mod;
  48.     return dp[i][j] = ans%mod;
  49. }
  50.  
  51.  
  52.  
  53.  
  54. void solve(){
  55.   cin>>n;
  56.   grid.assign(n,vector<char>(n));
  57.     dp.assign(n+3,vector<ll>(n+3,-1));
  58.     for(int i=0;i<n;i++){
  59.         for(int j=0;j<n;j++){
  60.             cin>>grid[i][j];
  61.         }
  62.     }
  63.  
  64.     cout<<rec(0,0)<<nl;
  65.  
  66.  
  67.  
  68.  
  69.  
  70. }
  71.  
  72. int main(){
  73.     Fast_IO();
  74. int t =1;
  75. //cin>>t;
  76. while(t--){
  77. solve();
  78. }
  79. return 0;
  80. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement