Iam_Sandeep

Untitled

Sep 19th, 2022
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from functools import lru_cache
  2. def find(costs,gp):
  3.     n=len(gp)
  4.     full_mask = 1<<n-1
  5.     @lru_cache()
  6.     def help(i,mpos):
  7.         if i==len(costs) or mpos==full_mask:
  8.             return 0
  9.         ans = 0
  10.         for y in range(len(gp)):
  11.             if (mpos & 1<<y) ==0:
  12.                 modified_mpos = mpos|1<<y
  13.                 cost_for_alloting = sum(costs[i:i+gp[y]+1])
  14.                 ans=max(ans,cost_for_alloting+help(i+gp[y],modified_mpos))
  15.         return ans
  16.     return help(0,0)
Advertisement
Add Comment
Please, Sign In to add comment