josiftepe

Untitled

Nov 7th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. using namespace std;
  5. const int MOD = 1e9 + 7;
  6. int n;
  7. char mat[1001][1001];
  8. int number_of_ways[1001][1001]; // na kolku nacini mozam da pristignam od poleto (0, 0) do poleto (i, j)
  9. void add_self(int &a, int b) {
  10.     a += b;
  11.     if(a >= MOD) {
  12.         a -= MOD;
  13.     }
  14. }
  15. int main(){
  16.     cin >> n;
  17.     for(int i = 0; i < n; ++i) {
  18.         for(int j = 0; j < n; ++j) {
  19.             cin >> mat[i][j];
  20.             number_of_ways[i][j] = 0;
  21.         }
  22.     }
  23.     if(mat[0][0] != '*') {
  24.         number_of_ways[0][0] = 1;
  25.     }
  26.     for(int i = 0; i < n; ++i) {
  27.         for(int j = 0; j < n; ++j) {
  28.             if(i + 1 < n and mat[i + 1][j] != '*') { // down
  29.                 add_self(number_of_ways[i + 1][j], number_of_ways[i][j]);
  30.             }
  31.             if(j + 1 < n and mat[i][j + 1] != '*') {// right
  32.                 add_self(number_of_ways[i][j + 1], number_of_ways[i][j]);
  33.             }
  34.            
  35.         }
  36.     }
  37. //    for(int i = 0; i < n; ++i) {
  38. //        for(int j = 0; j < n; ++j) {
  39. //            cout << number_of_ways[i][j] << " ";
  40. //        }
  41. //        cout << endl;
  42. //    }
  43.     cout << number_of_ways[n - 1][n - 1] << endl;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment