Untitled
unknown
plain_text
2 years ago
857 B
9
Indexable
Never
bin_list = [] def Try(cnt , n , s): if cnt == n: cnt_1 = 0 for c in s: if c == "1": cnt_1 += 1 if cnt_1 > 1: bin_list.append(s) else: Try(cnt+1,n,s + "0") Try(cnt+1,n,s + "1") def check_incresae(tmp_list): flag = all(i < j for i, j in zip(tmp_list, tmp_list[1:])) return flag if __name__ == "__main__": n = int(input()) a = [int(i) for i in input().split()] Try(0,n,"") tmp_res = [] for l in bin_list: tmp = [] for i in range(n): if l[i] == "1": tmp.append(a[i]) if check_incresae(tmp): tmp = [str(x) for x in tmp] tmp_res.append(tmp) res = sorted(tmp_res) for l in res: for ele in l: print(ele,end = " ") print()