In [67]:
pageHeight = 28.0
In [68]:
textHeight = 0.8
textSpaceheight = 0.6
In [69]:
lineNo = 10000
In [80]:
lineAssignInfo = dict()
In [71]:
n = lineNo
In [81]:
def cost(n):
global lineAssignInfo
global textHeight
global textSpaceheight
if n == 0:
lineAssignInfo[n] = 0
return 1
min_cost = float("inf")
min_p = -1
cost(n-1)
for p in range(n):
if p < lineAssignInfo[n-1]:
pass #cost = float("inf")
else:
input_texts_len_in_p = len([k for k, v in lineAssignInfo.items() if v == p])
input_texts_height_in_p = input_texts_len_in_p * (textHeight + textSpaceheight) - textSpaceheight
if input_texts_height_in_p + textSpaceheight + textHeight > pageHeight:
pass #cost = float("inf")
else:
temp_max_page_no = max(p, max(lineAssignInfo.keys()))
if min_cost > temp_max_page_no:
min_cost = temp_max_page_no
min_p = p
lineAssignInfo[n] = min_p
return min
In [82]:
cost(100)
print(lineAssignInfo)
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 1, 21: 1, 22: 1, 23: 1, 24: 1, 25: 1, 26: 1, 27: 1, 28: 1, 29: 1, 30: 1, 31: 1, 32: 1, 33: 1, 34: 1, 35: 1, 36: 1, 37: 1, 38: 1, 39: 1, 40: 2, 41: 2, 42: 2, 43: 2, 44: 2, 45: 2, 46: 2, 47: 2, 48: 2, 49: 2, 50: 2, 51: 2, 52: 2, 53: 2, 54: 2, 55: 2, 56: 2, 57: 2, 58: 2, 59: 2, 60: 3, 61: 3, 62: 3, 63: 3, 64: 3, 65: 3, 66: 3, 67: 3, 68: 3, 69: 3, 70: 3, 71: 3, 72: 3, 73: 3, 74: 3, 75: 3, 76: 3, 77: 3, 78: 3, 79: 3, 80: 4, 81: 4, 82: 4, 83: 4, 84: 4, 85: 4, 86: 4, 87: 4, 88: 4, 89: 4, 90: 4, 91: 4, 92: 4, 93: 4, 94: 4, 95: 4, 96: 4, 97: 4, 98: 4, 99: 4, 100: 5}