Advertisement
_rashed

FbHkrCup 18-R1-A

Jul 1st, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7. const ll MOD =1e9 + 7;
  8.  
  9. ll mem[3][1000][2];
  10. char graph[3][1000];
  11. ll n;
  12. ll solve(int r, int c, int d) {
  13.     if(r == 2 && c == n && d == 0) {
  14.         return 1;
  15.     }
  16.     if(r < 0 || r > 2 || c < 0 || c > n-1 || graph[r][c] == '#') {
  17.         return 0;
  18.     }
  19.     if(mem[r][c][d] != -1) {
  20.         return mem[r][c][d];
  21.     }
  22.     ll &ret = mem[r][c][d];
  23.     ret = 0;
  24.     if(d == 1) {
  25.         ret = solve(r,c+1,0)%MOD;
  26.     }
  27.     else {
  28.         ret = (solve(r-1,c,1) + solve(r+1,c,1))%MOD;
  29.     }
  30.     return ret;
  31. }
  32.  
  33. int main()
  34. {
  35.     freopen("let_it_flow_input.txt","r",stdin);
  36.     freopen("out.txt","w",stdout);
  37.     ios_base::sync_with_stdio(false);
  38.     cin.tie(NULL);
  39.     cout.tie(NULL);
  40.     int t;
  41.     cin >> t;
  42.     for(int ti = 1; ti <= t; ti++) {
  43.         cin >> n;
  44.         for(int i = 0; i < 3; i++) {
  45.             for(int j = 0; j < n; j++) {
  46.                 cin >> graph[i][j];
  47.                 for(int d = 0; d < 2; d++) {
  48.                     mem[i][j][d] = -1;
  49.                 }
  50.             }
  51.         }
  52.         cout << "Case #" << ti << ": " << solve(0,0,0) << "\n";
  53.     }
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement