Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- int n, k;
- int ar[101] = {};
- void f(int cur);
- void print();
- int main(){
- cin >> n >> k;
- f(0);
- return 0;
- }
- void f(int cur){
- if (cur == k){
- print();
- return;
- }
- if (cur == 0){
- for (int i = 1; i <= n - k + 1; i++){
- ar[cur] = i;
- f(cur + 1);
- }
- }else{
- for (int i = ar[cur - 1] + 1; i <= n - (k - cur) + 1; i++){
- ar[cur] = i;
- f(cur + 1);
- }
- }
- }
- void print(){
- for (int i = 0; i < k; i++)
- cout << ar[i] << " ";
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement