{"id":"02db3a5b-ce89-41ea-9331-fec7a576cbdb","name":"Unbounded Knapsack","description":"1. You are given a number n, representing the count of items.\r\n2. You are given n numbers, representing the values of n items.\r\n3. You are given n numbers, representing the weights of n items.\r\n3. You are given a number \"cap\", which is the capacity of a bag you've.\r\n4. You are required to calculate and print the maximum value that can be created in the bag without \r\n overflowing it's capacity.\r\nNote -> Each item can be taken any number of times. You are allowed to put the same item again \r\n and again.","inputFormat":"A number n\r\nv1 v2 .. n number of elements\r\nw1 w2 .. n number of elements\r\nA number cap","outputFormat":"A number representing the maximum value that can be created in the bag without overflowing it's capacity","constraints":"1 &lt;= n &lt;= 20\r\n0 &lt;= v1, v2, .. n elements &lt;= 50\r\n0 &lt; w1, w2, .. n elements &lt;= 10\r\n0 &lt; cap &lt;= 10","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nvoid unboundedKnapsack(int n,vector<int> val, vector<int> weight,int cap){\n \n// write your code here\n \n}\n\n\nint main() {\n\n int n;\n cin>>n;\n vector<int> val(n);\n for (int i = 0; i < n; i++) {\n\n cin>>val[i];\n }\n vector<int> weight(n);\n for (int i = 0; i < n; i++) {\n cin>>weight[i];\n }\n int cap;\n cin>>cap;\n \n unboundedKnapsack(n,val, weight,cap);\n \n\n}"},"java":{"code":"import java.io.*;\r\n\timport java.util.*;\r\n\r\n\tpublic class Main {\r\n\r\n\t public static void main(String[] args) throws Exception {\r\n\r\n\t }\r\n\t}"},"python":{"code":"def unbounded_knapSack(cap, wt, val, n):\n\n# write your code here\n\nn = int(input())\n\nst1 = input()\nv=st1.split()\nval=[int(i) for i in v]\n\nst2 = input()\nw = st2.split()\nwt = [int(j) for j in w]\n\ncap = int(input()) \n \nprint(unbounded_knapSack(cap, wt, val, n))"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n15 14 10 45 30\r\n2 5 1 3 4\r\n7","sampleOutput":"100","questionVideo":"https://www.youtube.com/embed/jgps7MXtKRQ?end=133","hints":[],"associated":[{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"97159b90-5208-4c20-8d17-b16483df2a66","name":"What is the time complexity of solving unbounded knapsack if n is the total number of items and c is the capacity of the bag?","slug":"what-is-the-time-complexity-of-solving-unbounded-knapsack-if-n-is-the-total-number-of-items-and-c-is-the-capacity-of-the-bag","type":4},{"id":"a0992ad9-bc86-465c-b761-fe416e3b6fb2","name":"In unbounded knapsack, we seek _______ of items","slug":"in-unbounded-knapsack-we-seek-of-items","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"a3f86b88-e8f4-4b33-bc95-0ec6731b43b1","name":"Unbounded Knapsack","slug":"unbounded-knapsack","type":1}],"next":{"id":"0802c91b-a2f7-4ae7-a4ba-0a3199e2afb4","name":"Unbounded Knapsack","type":3,"slug":"unbounded-knapsack"},"prev":{"id":"52e053b3-7680-4950-83fe-6d79f5074a38","name":"Zero One Knapsack","type":3,"slug":"zero-one-knapsack"}}}

Unbounded Knapsack

1. You are given a number n, representing the count of items. 2. You are given n numbers, representing the values of n items. 3. You are given n numbers, representing the weights of n items. 3. You are given a number "cap", which is the capacity of a bag you've. 4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity. Note -> Each item can be taken any number of times. You are allowed to put the same item again and again.

{"id":"02db3a5b-ce89-41ea-9331-fec7a576cbdb","name":"Unbounded Knapsack","description":"1. You are given a number n, representing the count of items.\r\n2. You are given n numbers, representing the values of n items.\r\n3. You are given n numbers, representing the weights of n items.\r\n3. You are given a number \"cap\", which is the capacity of a bag you've.\r\n4. You are required to calculate and print the maximum value that can be created in the bag without \r\n overflowing it's capacity.\r\nNote -> Each item can be taken any number of times. You are allowed to put the same item again \r\n and again.","inputFormat":"A number n\r\nv1 v2 .. n number of elements\r\nw1 w2 .. n number of elements\r\nA number cap","outputFormat":"A number representing the maximum value that can be created in the bag without overflowing it's capacity","constraints":"1 &lt;= n &lt;= 20\r\n0 &lt;= v1, v2, .. n elements &lt;= 50\r\n0 &lt; w1, w2, .. n elements &lt;= 10\r\n0 &lt; cap &lt;= 10","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n\nusing namespace std;\n\nvoid unboundedKnapsack(int n,vector<int> val, vector<int> weight,int cap){\n \n// write your code here\n \n}\n\n\nint main() {\n\n int n;\n cin>>n;\n vector<int> val(n);\n for (int i = 0; i < n; i++) {\n\n cin>>val[i];\n }\n vector<int> weight(n);\n for (int i = 0; i < n; i++) {\n cin>>weight[i];\n }\n int cap;\n cin>>cap;\n \n unboundedKnapsack(n,val, weight,cap);\n \n\n}"},"java":{"code":"import java.io.*;\r\n\timport java.util.*;\r\n\r\n\tpublic class Main {\r\n\r\n\t public static void main(String[] args) throws Exception {\r\n\r\n\t }\r\n\t}"},"python":{"code":"def unbounded_knapSack(cap, wt, val, n):\n\n# write your code here\n\nn = int(input())\n\nst1 = input()\nv=st1.split()\nval=[int(i) for i in v]\n\nst2 = input()\nw = st2.split()\nwt = [int(j) for j in w]\n\ncap = int(input()) \n \nprint(unbounded_knapSack(cap, wt, val, n))"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n15 14 10 45 30\r\n2 5 1 3 4\r\n7","sampleOutput":"100","questionVideo":"https://www.youtube.com/embed/jgps7MXtKRQ?end=133","hints":[],"associated":[{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"97159b90-5208-4c20-8d17-b16483df2a66","name":"What is the time complexity of solving unbounded knapsack if n is the total number of items and c is the capacity of the bag?","slug":"what-is-the-time-complexity-of-solving-unbounded-knapsack-if-n-is-the-total-number-of-items-and-c-is-the-capacity-of-the-bag","type":4},{"id":"a0992ad9-bc86-465c-b761-fe416e3b6fb2","name":"In unbounded knapsack, we seek _______ of items","slug":"in-unbounded-knapsack-we-seek-of-items","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"a3f86b88-e8f4-4b33-bc95-0ec6731b43b1","name":"Unbounded Knapsack","slug":"unbounded-knapsack","type":1}],"next":{"id":"0802c91b-a2f7-4ae7-a4ba-0a3199e2afb4","name":"Unbounded Knapsack","type":3,"slug":"unbounded-knapsack"},"prev":{"id":"52e053b3-7680-4950-83fe-6d79f5074a38","name":"Zero One Knapsack","type":3,"slug":"zero-one-knapsack"}}}
plane

Editor


Loading...

Unbounded Knapsack

easy

1. You are given a number n, representing the count of items. 2. You are given n numbers, representing the values of n items. 3. You are given n numbers, representing the weights of n items. 3. You are given a number "cap", which is the capacity of a bag you've. 4. You are required to calculate and print the maximum value that can be created in the bag without overflowing it's capacity. Note -> Each item can be taken any number of times. You are allowed to put the same item again and again.

Constraints

1 <= n <= 20 0 <= v1, v2, .. n elements <= 50 0 < w1, w2, .. n elements <= 10 0 < cap <= 10

Format

Input

A number n v1 v2 .. n number of elements w1 w2 .. n number of elements A number cap

Output

A number representing the maximum value that can be created in the bag without overflowing it's capacity

Example

Sample Input

5 15 14 10 45 30 2 5 1 3 4 7

Sample Output

100

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode