Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("date.in");
- ofstream fout("date.out");
- int n;
- int st[20];
- void Afisare()
- {
- int i;
- for(i=1;i<=n;++i)
- fout<<st[i]<<" ";
- fout<<"\n";
- }
- void Back(int k)
- {
- if(k==n+1)
- Afisare();
- int i;
- for(i=1;i<=n;i++)
- {
- //incerc sa generez toate permutarile care il au pe pozitia
- //k pe i
- //verific daca i-ul este disponibil(nu mai apare in permutarea actuala)
- bool disponibil=true;
- int j;
- for(j=1;j<k;j++)
- if(st[j]==i)
- disponibil=false;
- if(disponibil)
- {
- st[k] = i;
- Back(k+1);
- }
- }
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen ("date.in","r",stdin);
- freopen ("date.out","w",stdout);
- #endif
- n=1;
- Back(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement