2017-09-11 21:30:16 +08:00

25 lines
783 B
Python

def gen_block(length, mini):
def gen_iter(result, lst, rest_count, rest_len, mini):
if not rest_count:
result.append(lst)
else:
rest_count -= 1
for this_len in range(mini, rest_len - rest_count * mini + 1):
gen_iter(result, lst + [this_len], rest_count, rest_len - this_len, mini)
for block_count in range(1, int((length + 1) / (mini + 1)) + 1):
block_maxlen = length - block_count + 1
result = []
gen_iter(result, [], block_count, block_maxlen, mini)
for item in result:
yield item
def put(length, lst):
return length - sum(lst) - len(lst), len(lst) - 2
def count(length, mini):
for x in gen_block(length, mini):
print(x)
print(count(50, 3))