fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int memo[33];
  7.  
  8. int mistakes_count(int n)
  9. {
  10. if (memo[n] == -1) {
  11. int mx = 0;
  12. for(int i = 1; i < n; ++i) { // 1 must be honest
  13. int catr = i, catw = n - i; // If all are honest, repeat
  14. if(catr > catw) {
  15. mx = std::max(mx, mistakes_count(catr));
  16. } else {
  17. mx = std::max(mx, 1 + mistakes_count(catr));
  18. }
  19. }
  20. memo[n] = mx;
  21. }
  22. return memo[n];
  23. }
  24.  
  25. int main() {
  26. for(int i = 1; i <= 32; ++i) memo[i] = -1;
  27. cout << mistakes_count(32);
  28. return 0;
  29. }
  30.  
  31.  
  32.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
5