Example 2 Input: grid 1 -2 Output: 8 Explanation: Maximum non-negative product (in red) is 1-1.-2.-4-1= 8. Example 3 Input: grid Output: 0 Explanation: Maximum non-negative product (in red) is 1.0.-4 = 0. Example 4 Input: 1 4 4 0] grid =-2 0 0 1 -1 1 1 Output: 2 Explanation: Maximum non-negative product (in red) is 1.-2-1.-1 1.1=2. You must solve this using both a bottom-up Dynamic Programming algorithm and a memoized recursive algorithm. (a) Pseudocode • Define the subproblems for your DP solution for finding the maximum non-negative product value. • Give a recursive formulation, including the base cases, to solve this problem. • What is the running time of your solution? • Write a DP algorithm (give pseudocode) that outputs the maximum non-negative product value. • Write a memoized algorithm (give pseudocode) that outputs the maximum non-negative product value. (b) Source Code • Write your solution in Python, C, C++, Java, or JavaScript.
Example 2 Input: grid 1 -2 Output: 8 Explanation: Maximum non-negative product (in red) is 1-1.-2.-4-1= 8. Example 3 Input: grid Output: 0 Explanation: Maximum non-negative product (in red) is 1.0.-4 = 0. Example 4 Input: 1 4 4 0] grid =-2 0 0 1 -1 1 1 Output: 2 Explanation: Maximum non-negative product (in red) is 1.-2-1.-1 1.1=2. You must solve this using both a bottom-up Dynamic Programming algorithm and a memoized recursive algorithm. (a) Pseudocode • Define the subproblems for your DP solution for finding the maximum non-negative product value. • Give a recursive formulation, including the base cases, to solve this problem. • What is the running time of your solution? • Write a DP algorithm (give pseudocode) that outputs the maximum non-negative product value. • Write a memoized algorithm (give pseudocode) that outputs the maximum non-negative product value. (b) Source Code • Write your solution in Python, C, C++, Java, or JavaScript.
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
100%
![Example 2
Input:
2 1
grid
3
1.
Output: 8
Explanation: Maximum non-negative product (in red) is 1.1.-2.-4-1= 8.
Example 3
Input:
ena -
3
grid
Output: 0
Explanation: Maximum non-negative product (in red) is 1.0.-4 = 0.
Example 4
Input:
1
grid
-2
0 1
1
-1
1.
1.
Output: 2
Explanation: Maximum non-negative product (in red) is 1.-2.1.-1-1.1 = 2.
You must solve this using both a bottom-up Dynamic Programming algorithm and a memoized
recursive algorithm.
(a) Pseudocode
• Define the subproblems for your DP solution for finding the maximum non-negative product
value.
• Give a recursive formulation, including the base cases, to solve this problem.
• What is the running time of your solution?
• Write a DP algorithm (give pseudocode) that outputs the maximum non-negative product
value.
• Write a memoized algorithm (give pseudocode) that outputs the maximum non-negative
product value.
(b) Source Code
• Write your solution in Python, C, C++, Java, or JavaScript.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F646a794d-e587-473e-a1b8-2a8879d17700%2F02adeabb-1ebd-4b8d-9d13-76b0c994ca02%2Fkzalhbs_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Example 2
Input:
2 1
grid
3
1.
Output: 8
Explanation: Maximum non-negative product (in red) is 1.1.-2.-4-1= 8.
Example 3
Input:
ena -
3
grid
Output: 0
Explanation: Maximum non-negative product (in red) is 1.0.-4 = 0.
Example 4
Input:
1
grid
-2
0 1
1
-1
1.
1.
Output: 2
Explanation: Maximum non-negative product (in red) is 1.-2.1.-1-1.1 = 2.
You must solve this using both a bottom-up Dynamic Programming algorithm and a memoized
recursive algorithm.
(a) Pseudocode
• Define the subproblems for your DP solution for finding the maximum non-negative product
value.
• Give a recursive formulation, including the base cases, to solve this problem.
• What is the running time of your solution?
• Write a DP algorithm (give pseudocode) that outputs the maximum non-negative product
value.
• Write a memoized algorithm (give pseudocode) that outputs the maximum non-negative
product value.
(b) Source Code
• Write your solution in Python, C, C++, Java, or JavaScript.
![Problem 1> Maximum Non-Negative Product in a Matrix
You are given a rows x cols matrix grid. Initially, you are located at the top-left corner (0,0)
and, in each step, you can only move right or down in the matrix.
Among all possible paths starting from the top-left corner (0,0) and ending in the bottom-right
corner (rows – 1, cols - 1), find the path with the maximum non-negative product. The product
of a path is the product of all integers in the grid cells visited along the path.
Return the maximum non-negative product mod 10° + 7. If the maximum product is negative,
return –1.
Note that the modulo is performed after getting the maximum product.
Example 1
Input:
-2
grid=
-3
-3
-3
-2
Output: -1
Explanation: It's not possible to get non-negative product in the path from (0, 0) to (2, 2), so
return -1.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F646a794d-e587-473e-a1b8-2a8879d17700%2F02adeabb-1ebd-4b8d-9d13-76b0c994ca02%2Fopzw0hd_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Problem 1> Maximum Non-Negative Product in a Matrix
You are given a rows x cols matrix grid. Initially, you are located at the top-left corner (0,0)
and, in each step, you can only move right or down in the matrix.
Among all possible paths starting from the top-left corner (0,0) and ending in the bottom-right
corner (rows – 1, cols - 1), find the path with the maximum non-negative product. The product
of a path is the product of all integers in the grid cells visited along the path.
Return the maximum non-negative product mod 10° + 7. If the maximum product is negative,
return –1.
Note that the modulo is performed after getting the maximum product.
Example 1
Input:
-2
grid=
-3
-3
-3
-2
Output: -1
Explanation: It's not possible to get non-negative product in the path from (0, 0) to (2, 2), so
return -1.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education