Sanath12345

Untitled

May 11th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. //Problem link :
  2. //done by sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  24. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  25. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  26. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  27. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  28. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  29. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  30.  
  31. void err(istream_iterator<string> it){}
  32. template<typename T,typename... Args>
  33. void err(istream_iterator<string> it,T a,Args... args){
  34. cout<<*it<<" = "<<a<<endl;
  35. err(++it,args...);
  36. }
  37.  
  38. void file_i_o(){
  39. ios_base::sync_with_stdio(false);
  40.  
  41. cin.tie(0);
  42. cout.tie(0);
  43. #ifndef ONLINE_JUDGE
  44. freopen("input.txt","r",stdin);
  45. freopen("output.txt","w",stdout);
  46. #endif
  47. }
  48. ll solve(vector<vector<char>> grid,vector<vi> &dp,int n,int x,int y){
  49. if(x==n-1 and y==n-1) return 1;
  50. if(x>n-1 or y>n-1) return 0;
  51. if(grid[x][y]=='*') return 0;
  52. if(dp[x][y]!=-1) return dp[x][y];
  53. ll ans=0;
  54. ans=(ans+solve(grid,dp,n,x+1,y))%mod;
  55. ans=(ans+solve(grid,dp,n,x,y+1))%mod;
  56. dp[x][y]=ans;
  57. return ans;
  58. }
  59. int main(){
  60. file_i_o();
  61. clock_t begin=clock();
  62. int n;
  63. cin>>n;
  64. vector<vector<char>> grid(n+1,vector<char>(n+1));
  65. loop(i,0,n-1){
  66. loop(j,0,n-1) cin>>grid[i][j];
  67. }
  68. vector<vi> dp(n+1,vi(n+1,-1));
  69. if(grid[0][0]=='*' or grid[n-1][n-1]=='*') cout<<"0"<<endl;
  70. else cout<<solve(grid,dp,n,0,0)<<endl;
  71. #ifndef ONLINE_JUDGE
  72. clock_t end=clock();
  73. cout<<"\n\n\nExecuted in :"<<double(end-begin)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
  74. #endif
  75. }
Advertisement
Add Comment
Please, Sign In to add comment