This problem is simple. You have N items numbered 1 to N. Each item has a weight Wi But wait, you might be wondering why the items don't have values. Well, that's because this isn't your normal knapsack. This is an even more basic knapsack. There's no need to worry about values, because you will be given the capacity of your knapsack. Instead of maximizing a value, just count how many ways you can fill your knapsack without exceeding capacity. For example, if you have 3 items with weights 3, 5, and 7 and your knapsack has a capacity 9, there are 5 ways to fill the knapsack as follows:
This problem is simple. You have N items numbered 1 to N. Each item has a weight Wi But wait, you might be wondering why the items don't have values. Well, that's because this isn't your normal knapsack. This is an even more basic knapsack. There's no need to worry about values, because you will be given the capacity of your knapsack. Instead of maximizing a value, just count how many ways you can fill your knapsack without exceeding capacity. For example, if you have 3 items with weights 3, 5, and 7 and your knapsack has a capacity 9, there are 5 ways to fill the knapsack as follows:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible. Apply dynamic
Hint: Approach the problem with 2D Dynamic Programming.
Output Format
Output one line containing a single integer containing the answer as described in the problem statement. This number must be output mod 109 + 7.
Sample Input 0:
3 9
3
5
7
Sample Output 0:
5
Sample Input 1:
3 23
15
16
15
Sample Output 1:
4
Sample Input 2:
3 6
1
2
3
Sample Output 2:
8
The actual code:
def solve(n,c,ws):
# compute and return answer here # place 2 nested for loops here
MOD = 1000000007 n, c = list(map(int,input().rstrip().split(" "))) ws = [int(input().rstrip()) for i in range(n)] print(solve(n,c,ws)) |
|
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education