th0m45s5helby

Untitled

May 7th, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. def solve(l,ans, K, store, skillset):
  2.     if (ans == K):
  3.         cost=0
  4.         maxbrush=0
  5.         for i in range(len(store)):
  6.             cost+=stipend[store[i][1]]
  7.             maxbrush=max(maxbrush,brushes[store[i][1]])
  8.         cost+=k*maxbrush
  9.         costarr.append(cost)
  10.         return
  11.     for i in range(l, len(skillset), 1):
  12.         if (ans + skillset[i] > K):
  13.             continue
  14.         if (i > l and skillset[i] == skillset[i - 1]):
  15.             continue
  16.         store.append([skillset[i],i])
  17.         solve(i + 1, ans + skillset[i],K, store, skillset)
  18.         store.remove(store[len(store) - 1])
  19.  
  20. m=int(input())
  21. n=int(input())
  22. k=int(input())
  23. stipend=[]
  24. brushes=[]
  25. skills=[]
  26. costarr=[]
  27. maxbrush=0
  28. for i in range(n):
  29.     stipend.append(int(input()))
  30. for i in range(n):
  31.     brushes.append(int(input()))
  32. for i in range(n):
  33.     skills.append(int(input(),2))
  34. mx = int("1"*m,2)
  35. skills.sort()
  36. temp=[]
  37. solve(0,0,mx,temp,skills)
  38. if len(costarr)==0:print(-1)
  39. else:
  40.     print(min(costarr))
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment