d = [1] *13 for i in range(2, 13): d[i] = 1 + 2 *d[i-1] d[0] = 0 f = [float('inf')] * 13 f[0] = 0 f[1] = 1 for i in range(1, 13): for j in range(1, i+1): f[i] = min(f[i], f[j]*2 + d[i-j]) for i in range(1, 13): print f[i]