Advertisement
pexea12

Lรขm

Sep 25th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, k;
  6. int a[100];
  7. bool select[100];
  8.  
  9. void print(int a[], int n) {
  10.     cout << endl;
  11.     for (int i = 1; i <= n; ++i)
  12.         cout << a[i] << " ";
  13. }
  14.  
  15. void list(int k, int pos) {
  16.     for (int i = 1; i <= n; ++i) {
  17.         if (!select[i]) {
  18.             a[pos] = i;
  19.             select[i] = true;
  20.             if (pos == k) print(a, k);
  21.             else list(k, pos + 1);
  22.             select[i] = false;
  23.         }
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.    
  30.     cout << "n = "; cin >> n;
  31.     cout << "k = "; cin >> k;
  32.    
  33.     for (int i = 1; i <= k; ++i) select[i] = false;
  34.    
  35.     list(k, 1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement