Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- int n, m, result[10], num[10];
- void DFS(int x) {
- if(x == m) {
- for(int i=0;i<x;i++) printf("%d ", result[i]);
- printf("\n");
- }
- else {
- for(int i=0;i<n;i++) {
- result[x] = num[i];
- if(x >= 1) {
- if(result[x] < result[x-1]) continue;
- }
- DFS(x+1);
- }
- }
- }
- int main() {
- scanf("%d %d", &n, &m);
- for(int i=0;i<n;i++) scanf("%d", &num[i]);
- sort(num, num+n);
- DFS(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement