fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, X[10], a[20];
  5.  
  6. bool kt(){
  7. int t=0, s=0;
  8. for (int i=1; i<=n; i++)
  9. if (X[i]==1) {
  10. t=i;
  11. s=i;
  12. break;
  13. }
  14. for (int i=t+1; i<=n; i++)
  15. if (X[i]==1){
  16. t=s;
  17. s=i;
  18. if (a[t]>a[s]) return false;
  19. }
  20. return (t<s);
  21. }
  22.  
  23. void xuat(){
  24. int j;
  25. for (j=1;j<=n; j++ ){
  26. if (X[j]==1){
  27. cout<<a[j]<<" ";
  28. }
  29. }
  30. cout<<endl;
  31. }
  32.  
  33. void try1(int i){
  34. int j;
  35. for(j=0; j<=1; j++){
  36. X[i]=j;
  37. if (i==n){
  38. if (kt())
  39. xuat();
  40. }
  41. else try1(i+1);
  42. }
  43. }
  44.  
  45. int main() {
  46. cin>>n;
  47. for (int i=1; i<=n; i++){
  48. cin>>a[i];
  49. }
  50. try1(1);
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5436KB
stdin
4
1 8 2 4
stdout
2 4 
1 4 
1 2 
1 2 4 
1 8