simple O(2^k) algorithm