Advertisement
a53

CainiSiPisici1

a53
Nov 12th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. char A[3]="CP";
  8.  
  9. int c , p , x[21] , n;
  10.  
  11. void Afisare(int L)
  12. {
  13. for(int i = 1 ; i <= L ; i ++)
  14. cout << A[x[i]];
  15. cout << '\n';
  16. }
  17.  
  18. bool OK(int k)
  19. {
  20. if(k == 1)
  21. if(x[k] != 0)
  22. return false;
  23. if(k == n)
  24. if(x[k] != 1)
  25. return false;
  26. if(c < 0 || p < 0)
  27. return false;
  28. if(k > 2)
  29. if(x[k] == 0 && x[k-1] == 1 && x[k-2] == 0)
  30. return false;
  31. return true;
  32. }
  33.  
  34. void Back(int k)
  35. {
  36. for(int i = 0 ; i <= 1 ; i ++)
  37. {
  38. x[k] = i;
  39. if(i == 0)
  40. c --;
  41. else
  42. p --;
  43. if(OK(k))
  44. {
  45. if(k == n)
  46. Afisare(n);
  47. else
  48. Back(k + 1);
  49. }
  50. if(i == 0)
  51. c ++;
  52. else
  53. p ++;
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. cin >> c >> p;
  60. n = c + p;
  61. Back(1);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement