Advertisement
a53

back_ME

a53
Jan 1st, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int st[109],e,m,g,M,E;
  6. char v[109];
  7.  
  8. void afisare()
  9. {
  10. for (int i=1;i<=e+m;i++) cout<<v[st[i]];
  11. cout<<'\n';
  12. }
  13.  
  14. int valid(int k)
  15. {
  16. for (int i=1;i<=k-2;i++)
  17. {
  18. if (v[st[i]]=='E' && v[st[i+1]]=='E' && v[st[i+2]]=='E') return 0;
  19. if (v[st[i]]=='M' && v[st[i+1]]=='M' && v[st[i+2]]=='M') return 0;
  20. }
  21. if (k==e+m)
  22. {
  23. E=0,M=0;
  24. for (int i=1;i<=k;i++)
  25. {
  26. if (v[st[i]]=='E') E++;
  27. else M++;
  28. }
  29. if (E!=e || M!=m) return 0;
  30. }
  31. return 1;
  32. }
  33.  
  34. void bck(int k)
  35. {
  36. for (int i=0;i<=1;i++)
  37. {
  38. st[k]=i;
  39. if (valid(k))
  40. {
  41. if (k==e+m) g=1,afisare();
  42. else bck(k+1);
  43. }
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. cin>>e>>m;
  50. v[0]='E';
  51. v[1]='M';
  52. bck(1);
  53. if (g==0) cout<<"IMPOSIBIL";
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement