Advertisement
DarkTXYZ

CUBE-177: Escape

Feb 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int dp[1005][1005];
  6. int n,m;
  7.  
  8. int main(){
  9.     scanf("%d%d",&n,&m);
  10.     for(int i=1;i<=n;i++){
  11.         for(int j=1;j<=m;j++){
  12.             scanf("%d",&dp[i][j]);
  13.             if(dp[i][j])    dp[i][j] = -1;
  14.         }
  15.     }
  16.     for(int i=1;i<=n;i++){
  17.         for(int j=1;j<=m;j++){
  18.             if(dp[i][j]==-1)
  19.                 continue;
  20.             if(i==1 and j==1)
  21.                 dp[i][j] = 1;
  22.             else{
  23.                 if(dp[i][j-1]!=-1)
  24.                     dp[i][j] += dp[i][j-1];
  25.                 if(dp[i-1][j]!=-1)
  26.                     dp[i][j] += dp[i-1][j];
  27.                 dp[i][j] %= 1000000007;
  28.             }      
  29.         }
  30.     }
  31.     printf("%d",dp[n][m]);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement