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