#腾讯笔试#8.23 腾讯笔试第二题为什么回溯一个都过不了import sysclass Solution: def subset(self,s,n): self.res = [] partial = "" self.used = [False] * len(s) self.backtracking(partial,s) self.res.sort() return self.res[n-1] def backtracking(self,partial,s): if partial: self.res.append(partial) if len(partial) == len(s): return else: for i in range(len(s)): if not self.used[i]: if not partial or ord(s[i]) >= ord(partial[-1]): if i > 0 and s[i] == s[i-1] and not self.used[i - 1]: continue self.used[i] = True partial+=s[i] self.backtracking(partial,s) partial = partial[:-1] self.used[i] = Falsea = input().split()s = a[0]n = int(input().split()[0])print(str(Solution().subset(s,n)))