Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void perm(vector<int> & values, int n = 0) {
- const int count = values.size();
- if (n >= count - 1) {
- for (int i = 0; i < count; i++) {
- cout << values[i] << " ";
- }
- cout << endl;
- }
- else {
- perm(values, n + 1);
- for (int i = n + 1; i < count; i++) {
- swap(values[i], values[n]);
- perm(values, n + 1);
- swap(values[i], values[n]);
- }
- }
- }
- void select(const vector<int> & values, int m, int n, vector<int> & acc) {
- const int count = acc.size();
- if (n >= count) {
- perm(acc);
- }
- else {
- const int values_count = values.size();
- for (int i = m; i <= values_count - count + n; i++) {
- acc[n] = values[i];
- select(values, i + 1, n + 1, acc);
- }
- }
- }
- void process(const vector<int> & values, int count) {
- vector<int> acc(count);
- select(values, 0, 0, acc);
- }
- int main() {
- int n , count;
- cin >> n >> count;
- vector<int> values;
- values.reserve(n);
- for (int i = 1; i <= n; i++) {
- values.push_back(i);
- }
- process(values, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement