Advertisement
DontCallMeNuttoPleas

Escape<Unique Path DP>

Mar 22nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     int M=1e9+7;
  5.     int n,m;
  6.     scanf("%d%d",&n,&m);
  7.     int a[n][m];
  8.     for(int i=0;i<n;i++){
  9.         for(int j=0;j<m;j++){
  10.             scanf("%d",&a[i][j]);
  11.         }
  12.     }
  13.     long long b[n][m];
  14.     for(int i=0;i<n;i++){
  15.         for(int j=0;j<m;j++){
  16.             if(a[i][j]==1){
  17.                 b[i][j]=0;
  18.             }
  19.             else if(i==0&&j==0) b[i][j]=1;
  20.             else if(i==0) b[i][j]=b[i][j-1];
  21.             else if(j==0) b[i][j]=b[i-1][j];
  22.             else b[i][j]=(b[i-1][j]+b[i][j-1])%M;
  23.         }
  24.     }
  25.     printf("%lld",b[n-1][m-1]);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement