Advertisement
tankian202

Untitled

Sep 5th, 2023
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. ///x- megoldasok tombje
  4. ///k- rekurzio aktualis lepcsofoka
  5. /// p- hany elemu reszhalmazok(szamok lesznek)
  6. ///counter- counter :)))))))
  7. ///n-hatar
  8. bool igeretes(int x[],int k) {
  9.     for(int i=0; i<k; i++){
  10.         if (x[k] <= x[i]) {///ellenorizzuk a novekvo sorrendet "kigeneralt" reszhalmazokban
  11.        return false;
  12.         }
  13.     }
  14.     return true;
  15. }
  16.  
  17. int kiir(int x[],int k){
  18.     for(int i=0; i<=k; i++){
  19.         cout << x[i] << " ";
  20.     }
  21.     cout << "\n";
  22. }
  23. void backTracking(int x[], int k,int  p, int  &counter, int n) {
  24.     for (int i = 1; i <= n; ++i) {
  25.         x[k] = i;
  26.         if (igeretes(x, k)) {
  27.             if (k == p - 1) {
  28.                 counter++;
  29.                 kiir(x, k);
  30.             } else {
  31.                 backTracking(x, k + 1, p, counter, n);
  32.             }
  33.         }
  34.     }
  35. }
  36. int main() {
  37.     int p = 4;
  38.     int x[p];
  39.     int counter=0;
  40.     int n=6;
  41.     backTracking(x, 0, p, counter, n);
  42.     cout<<"\n"<< counter;
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement