Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- #define T \
- ll rrr; \
- cin >> rrr; \
- for (ll w1 = 0; w1 < rrr; w1++)
- #define cin(vec, a) for (ll i = 0; i < a && cin >> vec[i]; i++)
- #define cout(vec, a) for (ll i = 0; i < a && cout << vec[i] << " "; i++)
- #define MOD 1000000007
- #define PI 3.14159265
- #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #include <iostream>
- #define INF 1e9
- #define mod 1000000007
- #include <string>
- #define el '\n'
- #define sp ' '
- #define loop(n) for (int i = 0; i < n; i++)
- typedef long long ll;
- #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
- #define multi_ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
- void sasa()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- vector<vector<char>> v;
- ll n;
- vector<vector<ll>> memo(1005, vector<ll>(1005, -1));
- bool isvalid(int i, int j)
- {
- if (i < 0 || j < 0 || i >= n || j >= n || v[i][j] == '*')
- return false;
- return true;
- }
- ll grid_path(ll i, ll j, ll n, ll m)
- {
- if (i == n - 1 && j == m - 1)
- {
- return 1;
- }
- if (memo[i][j] != -1)
- return (memo[i][j] % mod);
- ll k = 0;
- if (isvalid(i + 1, j))
- {
- k = (k % mod + grid_path(i + 1, j, n, m) % mod) % mod;
- }
- if (isvalid(i, j + 1))
- {
- k = (k % mod + grid_path(i, j + 1, n, m) % mod) % mod;
- }
- return memo[i][j] = (k % mod);
- }
- void solve()
- {
- cin >> n;
- v = vector<vector<char>>(n, vector<char>(n));
- for (ll i = 0; i < n; i++)
- {
- for (ll j = 0; j < n; j++)
- {
- cin >> v[i][j];
- }
- }
- cout << grid_path(0, 0, n, n);
- }
- int main()
- {
- sasa();
- ll t = 1, i = 1;
- // cin >> t;
- while (t--)
- {
- // cout << "Case #" << i << ": ";
- solve();
- i++;
- if (!t)
- break;
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement