Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
643 B
12
Indexable
ans = []
count = 0

def record(a, n):
    global count
    ans.append([a[i] for i in range(1, n + 1)])
    count += 1

def back(pos, n, a, used):
    if pos == n + 1:
        record(a, n)
        return

    for i in range(1, n + 1):
        if not used[i]:
            a[pos] = i
            used[i] = True
            back(pos + 1, n, a, used)
            used[i] = False

def solve():
    global ans, count
    n, k = map(int, input().split())
    a = [0] * (n + 1)
    used = [False] * (n + 1)
    ans = []
    count = 0
    back(1, n, a, used)
    print(ans[k - 1])

if __name__ == "__main__":
    solve()
Leave a Comment