Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def find(costs,gp):
- n=len(gp)
- full_mask = 1<<n-1
- @lru_cache()
- def help(i,mpos):
- if i==len(costs) or mpos==full_mask:
- return 0
- ans = 0
- for y in range(len(gp)):
- if (mpos & 1<<y) ==0:
- modified_mpos = mpos|1<<y
- cost_for_alloting = sum(costs[i:i+gp[y]+1])
- ans=max(ans,cost_for_alloting+help(i+gp[y],modified_mpos))
- return ans
- return help(0,0)
Advertisement
Add Comment
Please, Sign In to add comment