Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int sol[100],n,nb,nf,m,y,x;
  5. int valid(int k)
  6. {/*for(int i=1;i<=k;i++)
  7. if(sol[i]<=x)
  8. nf++;
  9. else nb++;*/
  10. if(nf>y)
  11. {
  12. return 0;
  13. }
  14. if(nb>m-y)
  15. {
  16. return 0;
  17. }
  18. if(sol[k]<=sol[k-1]&&k>1)
  19. {
  20. return 0;
  21. }
  22. return 1;
  23. }
  24. void afis(int k)
  25. {
  26. for(int i=1;i<=k;i++)
  27. {
  28. cout<<sol[i]<<" ";
  29. }
  30. cout<<endl;
  31. }
  32. void backt(int k)
  33. {
  34. for(int i=1;i<=n;i++)
  35. {
  36. sol[k]=i;
  37. if(sol[k]<=x)nf++;
  38. else nb++;
  39. if(valid(k)==1)
  40. {
  41. if(k==m)
  42. {
  43. afis(k);
  44. }
  45. else
  46. {
  47. backt(k+1);
  48. }
  49. }
  50. if(sol[k]<=x)nf--;
  51. else nb--; }
  52. }
  53. int main()
  54. {
  55. cout<<"n=";
  56. cin>>n;
  57. cout<<"m=";
  58. cin>>m;
  59. cout<<"y=";
  60. cin>>y;
  61. cout<<"x=";
  62. cin>>x;
  63. backt(1);
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement