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
icon
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.
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Embedded software development
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education