SHARE
TWEET

Untitled

a guest Dec 13th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int S[10], n, l;
  5. bool valid(int k);
  6. bool solutie(int k);
  7. void afisare(int k, ofstream& of);
  8. void BK(int k, ofstream& of){
  9.     for(int i=1; i<=n; i++)
  10.     {
  11.         S[k] = i;
  12.         if(valid(k))
  13.             if(solutie(k))
  14.                 afisare(k, of);
  15.             else
  16.                 BK(k+1, of);
  17.     }
  18. }
  19. bool valid(int k){
  20.     for(int i=0; i<k; i++)
  21.     if(S[k] == S[i])
  22.         return false;
  23.     return true;
  24. }
  25. bool solutie(int k){
  26.     if(k == l)
  27.         return true;
  28.     return false;
  29. }
  30. void afisare(int k, ofstream& of){
  31.     for(int i=1; i<=l; i++ )
  32.         of<<S[i]<<" ";
  33.     of<<endl;
  34. }
  35. int main()
  36. {
  37.     ifstream read("aranjamente.in");
  38.     ofstream write("aranjamente.out");
  39.     read>>n>>l;
  40.     BK(1, write);
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top