Advertisement
Guest User

dp H

a guest
Mar 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. int n,m;
  5. bool matrica[1010][1010];
  6. ll dp[1010][1010];
  7. ll modulo=1000000007;
  8.  
  9. using namespace std;
  10. int main()
  11. {
  12. ios::sync_with_stdio(false);
  13. cin.tie(0);
  14.  
  15. cin>>n>>m;
  16. string s;
  17. for(int i=0;i<n;i++)
  18. {
  19. cin>>s;
  20. for(int j=0;j<m;j++)
  21. if(s[j]=='.')
  22. matrica[i][j]=true;
  23. }
  24. bool ok=true;
  25. for(int i=0;i<n;i++)
  26. if(ok && matrica[i][0])
  27. dp[i][0]=1;
  28. else
  29. ok=false;
  30. ok=true;
  31. for(int j=0;j<m;j++)
  32. if(ok && matrica[0][j])
  33. dp[0][j]=1;
  34. else
  35. ok=false;
  36.  
  37. for(int i=1;i<n;i++)
  38. for(int j=1;j<m;j++)
  39. if(matrica[i][j])
  40. dp[i][j]=(dp[i-1][j]+dp[i][j-1])%modulo;
  41.  
  42. cout<<dp[n-1][m-1];
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement