Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. #define pii pair<int, int>
  7.  
  8. map<pii, bool> states;
  9.  
  10. bool isPossible(pii currentPoint, pii finalPoint) {
  11.     if(currentPoint.first > finalPoint.first || currentPoint.second > finalPoint.second) return false;
  12.     if(currentPoint == finalPoint) return true;
  13.     if(states.count(currentPoint)) return states[currentPoint];
  14.     pii firstOption, secondOption;
  15.     firstOption = secondOption = currentPoint;
  16.     firstOption.first += firstOption.second;
  17.     secondOption.second += secondOption.first;
  18.     bool isReachable = isPossible(firstOption, finalPoint) || isPossible(secondOption, finalPoint);
  19.     return states[currentPoint] = isReachable;
  20. }
  21.  
  22. int main() {
  23.     pii start = pii(3, 2);
  24.     pii end = pii(8, 6);
  25.     cout << isPossible(start, end);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement