Advertisement
huutho_96

maxTime

Mar 17th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int max = 0;
  6.  
  7. //neu 1 trong 2 bang 0 thi ket thuc, a tang 1 thi b giam 2 va nguoc lai
  8. void maxTime(int a, int b, int count = 0)
  9. {
  10.     if (a == 0 || b == 0)
  11.     {
  12.         if (count > max) max = count;
  13.         return;
  14.     }
  15.     if (a <= 2 && b <= 2)
  16.     {
  17.         count += a > b ? a : b;
  18.         if (count > max) max = count;
  19.         return;
  20.     }
  21.  
  22.     if (a <= 2 && b >= 2)
  23.     {
  24.         maxTime(a + 1, b - 2, count + 1);
  25.         return;
  26.     }
  27.  
  28.     if (b <= 2 && a >= 2)
  29.     {
  30.         maxTime(a - 2, b + 1, count + 1);
  31.         return;
  32.     }
  33.  
  34.     maxTime(a + 1, b - 2, count + 1);
  35.     maxTime(a - 2, b + 1, count + 1);
  36. }
  37.  
  38.  
  39. void main()
  40. {
  41.     maxTime(12, 3);
  42.     cout << max;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement