This code is based on the assumption that the minimal cost is reached by recursively boxing the smallest 2 blocks together until you have only one block left. It's just an assumption, I don't know how to prove if it's really the minimal or not, but it does verify the 3 examples given:
def minimal_cost(blocks):
"""Returns the minimal cost to box all blocks.
For example:
>>> minimal_cost([1, 2, 3])
9
>>> minimal_cost([1,5,3,6,3,5,2,5,7,9,11,23,4,1,4])
310
>>> minimal_cost([101,213,42,98,2,74,21,4])
1341
"""
a = blocks
cost = 0
while len(a) > 1:
sorted_blocks = list(sorted(a))
a = [sum(sorted_blocks[:2])] + sorted_blocks[2:]
cost += a[0]
return cost
PS: In case you're not familiar with it, you can use the examples given in the comment as tests, using the kick ass
doctest module.