Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int max = 0;
- //neu 1 trong 2 bang 0 thi ket thuc, a tang 1 thi b giam 2 va nguoc lai
- void maxTime(int a, int b, int count = 0)
- {
- if (a == 0 || b == 0)
- {
- if (count > max) max = count;
- return;
- }
- if (a <= 2 && b <= 2)
- {
- count += a > b ? a : b;
- if (count > max) max = count;
- return;
- }
- if (a <= 2 && b >= 2)
- {
- maxTime(a + 1, b - 2, count + 1);
- return;
- }
- if (b <= 2 && a >= 2)
- {
- maxTime(a - 2, b + 1, count + 1);
- return;
- }
- maxTime(a + 1, b - 2, count + 1);
- maxTime(a - 2, b + 1, count + 1);
- }
- void main()
- {
- maxTime(12, 3);
- cout << max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement