Advertisement
IlidanBabyRage

87.cpp

Jun 25th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. int n, k;
  8. int ar[101] = {};
  9.  
  10. void f(int cur);
  11. void print();
  12.  
  13. int main(){
  14.  
  15.     cin >> n >> k;
  16.     f(0);
  17.     return 0;
  18. }
  19.  
  20. void f(int cur){
  21.     if (cur == k){
  22.         print();
  23.         return;
  24.     }
  25.     if (cur == 0){
  26.         for (int i = 1; i <= n - k + 1; i++){
  27.             ar[cur] = i;
  28.             f(cur + 1);
  29.         }
  30.     }else{
  31.         for (int i = ar[cur - 1] + 1; i <= n - (k - cur) + 1; i++){
  32.             ar[cur] = i;
  33.             f(cur + 1);
  34.         }
  35.     }
  36. }
  37.  
  38. void print(){
  39.     for (int i = 0; i < k; i++)
  40.         cout << ar[i] << " ";
  41.     cout << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement