Advertisement
Guest User

Combinari

a guest
Oct 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("combinari.in");
  4. ofstream fout("combinari.out");
  5. int val_min=1,val_max = 2,n,k;
  6. vector<int>sol;
  7.  
  8. bool valid()
  9. {
  10. for(auto i = sol.begin(); i != sol.end()-1 ; i++)
  11. {
  12. if(*i >= sol.back())
  13. {
  14. return 0;
  15. }
  16. }
  17. return 1;
  18. }
  19.  
  20. bool solutie()
  21. {
  22. return sol.size() == k;
  23. }
  24.  
  25. void prelucrare_sol()
  26. {
  27. for(const auto& it : sol)
  28. {
  29. //cout<<it<<' ';
  30. fout<<it<<' ';
  31. }
  32. //cout<<'\n';
  33. fout<<'\n';
  34. }
  35.  
  36. void backt()
  37. {
  38. for(int i=val_min; i<=val_max; i++)
  39. {
  40. sol.push_back(i); ///solutie candidata
  41. if(valid())
  42. {
  43. if(solutie())
  44. {
  45. prelucrare_sol();
  46. }
  47. else
  48. {
  49. backt();
  50. }
  51. }
  52. sol.pop_back();
  53. }
  54. }
  55.  
  56. int main()
  57. {
  58. //cin>>n>>k;
  59. fin>>n>>k;
  60. val_max=n;
  61. backt();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement