fork download
  1. #include <bits/stdc++.h>
  2. #define T int t;cin>>t;while(t--)
  3. #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
  4. #define ll long long
  5. #define endl '\n'
  6. using namespace std;
  7. const ll mod = 1e9 + 7;
  8. const ll N = 1e3 + 3;
  9. ll n, m;
  10. char grid[N][N];
  11. ll dp[N][N];
  12.  
  13. ll solve(ll i, ll j) {
  14. if (i == (n - 1) && j == (m - 1)) {
  15. return 1;
  16. }
  17. if (dp[i][j] >= 1) {
  18. return (dp[i][j]) % mod;
  19. }
  20. int o1 = 0, o2 = 0;
  21. if (grid[i + 1][j] != '#' && (i + 1) < n) o1 = solve(i + 1, j);
  22. if (grid[i][j + 1] != '#' && (j + 1) < m) o2 = solve(i, j + 1);
  23. return dp[i][j] = (o1 + o2) % mod;
  24. }
  25.  
  26. void Abady() {
  27. cin >> n >> m;
  28. for (int i = 0; i < n; i++) {
  29. for (int j = 0; j < m; j++) {
  30. cin >> grid[i][j];
  31. }
  32. }
  33. cout << (solve(0, 0)) % mod;
  34. }
  35.  
  36. int main() {
  37. fast;
  38. Abady();
  39. }
  40.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Standard output is empty