Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ this sodo code Consider the Collecting Apples problem given in class, rewrite the solution such that moving from start to end includes three types

c++
image text in transcribed
image text in transcribed
this sodo code
image text in transcribed
Consider the "Collecting Apples" problem given in class, rewrite the solution such that moving from start to end includes three types of moves: Right, Down, Right-Down. The Right-down move means that you can move diagonally. Also, black apples indicate that these are blocked and cannot be crossed as part of the path from start to end. The blocked cells are represented by negative values in the input. Write the function Count ingApples that takes as input a 2D array apples, and the values of two integers N and M(2N,2M). N represents the number of rows, and M represents the number of columns in the given apples 2D array. You will not be asked to read the values, the apples 2D array will be ready automatically and fed to your countingapples function. If there is no path from start to end, the maximum number of collected apples will be 0 . Also, if the start cell is a blocked one, there is no solution and the maximum number of collected apples will be 0 in this case as well. Output Your function should return the maximum number of apples that can be collected. Note: The program will be automatically tested by calling your Countingapples (int** apples, int N, int M) function. You are not allowed to change the signature of this function. Inside the function, you can use apples as a 2D array. You can define additional functions if you need. The function should return the maximum number of apples that can be collected. Memoized Solution COLLECT_APPLES (apples []) create array result [N][M] initialize result[] [] to 1 result[0][0]=apples[0][0] MAX_APPLES (N1,M1, apples, result) return result [N1][M1]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago