file = open("filename.txt", "r") f = file.readlines() # Creates an array of each line in the file, containing frazzlement on each line. def PageBreaks(T,d,f): n = len(f) # Initialize array M. for i in range(n+1): M[0][i] = [0,0] for p in range(T+1): M[p][0] = [0,0] # Update cost up to measure at index i at page p. for i in range(n+1): for p in range(T+1): minimum = float("inf") # min_j keeps track of which measure from 1-d the least costly page break is at min_j = 0 # Find minimum cost in range d at page before current page. for j in range(1,d+1): cost = M[p-1][i-j][0] if cost < minimum: minimum = cost min_j = j return M[T-1][n][0]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question