range queries and one graph
This commit is contained in:
31
CSES - CSES Problem Set/Dynamic_Programming/Grid_Paths.cpp
Normal file
31
CSES - CSES Problem Set/Dynamic_Programming/Grid_Paths.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// Grid Paths
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
ll dp[1001][1001];
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
vector<string> in(n);
|
||||
for (int i{}; i < n; i++) cin >> in[i];
|
||||
dp[0][0] = in[0][0] != '*';
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (in[0][i] == '*') continue;
|
||||
else dp[0][i] = dp[0][i - 1];
|
||||
}
|
||||
for (int i = 1; i < n; i++) {
|
||||
for (int j{}; j < n; j++) {
|
||||
if (in[i][j] == '*') continue;
|
||||
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
|
||||
dp[i][j] %= MOD;
|
||||
}
|
||||
}
|
||||
cout << dp[n-1][n-1] << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user