Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,m;
- char mat[1005][1005];
- int dp[1005][1005];
- int rek(int i, int j)
- {
- if(i==(n-1) && j==(m-1))
- {
- return 1;
- }
- if(dp[i][j]!=-1)
- {
- return dp[i][j];
- }
- int rez=0;
- int modul=1e9+7;
- if(mat[i][j+1]!='#' && j+1<m)
- {
- rez+=rek(i,j+1);
- rez%=modul;
- }
- if(mat[i+1][j]!='#' && i+1<n)
- {
- rez+=rek(i+1,j);
- rez%=modul;
- }
- dp[i][j]=rez;
- return rez;
- }
- int main()
- {
- cin>>n>>m;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- cin>>mat[i][j];
- }
- }
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- dp[i][j]=-1;
- }
- }
- cout<<rek(0,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement