josiftepe

Untitled

Nov 7th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 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. int main(){
  10.     cin >> n;
  11.     for(int i = 0; i < n; ++i) {
  12.         for(int j = 0; j < n; ++j) {
  13.             cin >> mat[i][j];
  14.             number_of_ways[i][j] = 0;
  15.         }
  16.     }
  17.     if(mat[0][0] != '*') {
  18.         number_of_ways[0][0] = 1;
  19.     }
  20.     for(int i = 0; i < n; ++i) {
  21.         for(int j = 0; j < n; ++j) {
  22.             if(i + 1 < n and mat[i + 1][j] != '*') { // down
  23.                 number_of_ways[i + 1][j] += number_of_ways[i][j];
  24.                 number_of_ways[i + 1][j] %= MOD;
  25.             }
  26.             if(j + 1 < n and mat[i][j + 1] != '*') {// right
  27.                 number_of_ways[i][j + 1] += number_of_ways[i][j];
  28.                 number_of_ways[i][j + 1] %= MOD;
  29.             }
  30.            
  31.         }
  32.     }
  33.     for(int i = 0; i < n; ++i) {
  34.         for(int j = 0; j < n; ++j) {
  35.             cout << number_of_ways[i][j] << " ";
  36.         }
  37.         cout << endl;
  38.     }
  39. //    cout << number_of_ways[n - 1][n - 1] << endl;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment