Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- const int MOD = 1e9 + 7;
- int n;
- char mat[1001][1001];
- int number_of_ways[1001][1001]; // na kolku nacini mozam da pristignam od poleto (0, 0) do poleto (i, j)
- int main(){
- cin >> n;
- for(int i = 0; i < n; ++i) {
- for(int j = 0; j < n; ++j) {
- cin >> mat[i][j];
- number_of_ways[i][j] = 0;
- }
- }
- if(mat[0][0] != '*') {
- number_of_ways[0][0] = 1;
- }
- for(int i = 0; i < n; ++i) {
- for(int j = 0; j < n; ++j) {
- if(i + 1 < n and mat[i + 1][j] != '*') { // down
- number_of_ways[i + 1][j] += number_of_ways[i][j];
- number_of_ways[i + 1][j] %= MOD;
- }
- if(j + 1 < n and mat[i][j + 1] != '*') {// right
- number_of_ways[i][j + 1] += number_of_ways[i][j];
- number_of_ways[i][j + 1] %= MOD;
- }
- }
- }
- for(int i = 0; i < n; ++i) {
- for(int j = 0; j < n; ++j) {
- cout << number_of_ways[i][j] << " ";
- }
- cout << endl;
- }
- // cout << number_of_ways[n - 1][n - 1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment