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.  
  31. cout<<endl;
  32. }
  33.  
  34. void try1(int i){
  35. int j;
  36. for(j=0; j<=1; j++){
  37. X[i]=j;
  38. if (i==n){
  39. if (kt())
  40. xuat();
  41. }
  42. else try1(i+1);
  43. }
  44. }
  45.  
  46. int main() {
  47. cin>>n;
  48. for (int i=1; i<=n; i++){
  49. cin>>a[i];
  50. }
  51. try1(1);
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5428KB
stdin
4
1 8 2 4
stdout
2 4 
1 4 
1 2 
1 2 4 
1 8