Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.setrecursionlimit(10**9)
- from functools import lru_cache
- def wordWrap(words, k, n):
- @lru_cache()
- def help(c,i):
- #print(c,i)
- if i==n:return (k-c+1)**3
- l=nums[i]
- ans=float('inf')
- rem=k-c
- if l<=rem:
- ans=min(ans,help(c+l+1,i+1))
- if c!=0:
- ans=min(ans,help(0,i)+(1+rem)**3)
- return ans
- nums=[len(i) for i in words]
- return help(0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement