Advertisement
heian

Untitled

May 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("date.in");
  6. ofstream fout("date.out");
  7.  
  8. int n;
  9. int st[20];
  10. bool viz[20];
  11.  
  12. void Afisare()
  13. {
  14. int i;
  15. for(i=1;i<=n;++i)
  16. fout<<st[i]<<" ";
  17. fout<<"\n";
  18. }
  19.  
  20. void Back(int k)
  21. {
  22. if(k==n+1)
  23. Afisare();
  24. int i;
  25. for(i=1;i<=n;i++)
  26. {
  27. //incerc sa generez toate permutarile care il au pe pozitia
  28. //k pe i
  29. //verific daca i-ul este disponibil(nu mai apare in permutarea actuala)
  30.  
  31. if(viz[i]==false)
  32. {
  33. st[k] = i;
  34. viz[i] = true;
  35. Back(k+1);
  36. viz[i] = false;
  37. }
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. #ifndef ONLINE_JUDGE
  44. freopen ("date.in","r",stdin);
  45. freopen ("date.out","w",stdout);
  46. #endif
  47. n=8;a
  48. Back(1);
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement