Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int n, m, result[10], num[10];
  6.  
  7. void DFS(int x) {
  8. if(x == m) {
  9. for(int i=0;i<x;i++) printf("%d ", result[i]);
  10. printf("\n");
  11. }
  12. else {
  13. for(int i=0;i<n;i++) {
  14. result[x] = num[i];
  15.  
  16. if(x >= 1) {
  17. if(result[x] < result[x-1]) continue;
  18. }
  19.  
  20. DFS(x+1);
  21. }
  22. }
  23. }
  24.  
  25. int main() {
  26. scanf("%d %d", &n, &m);
  27.  
  28. for(int i=0;i<n;i++) scanf("%d", &num[i]);
  29.  
  30. sort(num, num+n);
  31.  
  32. DFS(0);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement