Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solve(i,budget,n,h,p,dp):
- if(budget==0 or i==-1):
- return 0
- if(dp[i][budget]!=-1):
- return dp[i][budget]
- x,y=0,0
- if(budget-h[i]>=0):
- x=p[i]+solve(i-1,budget-h[i],n,h,p,dp)
- y=solve(i-1,budget,n,h,p,dp)
- dp[i][budget]=max(x,y)
- return dp[i][budget]
- n,x=map(int,input().split())
- h=list(map(int,input().split()))
- p=list(map(int,input().split()))
- dp=[[-1 for i in range(x+1)]for j in range(n+1)]
- print(solve(n-1,x,n,h,p,dp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement