Time: O(P(n,k)), Space: O(P(n, k) * k)