SlideShare a Scribd company logo
1 of 2
Download to read offline
As your reward for saving the Kingdom of Bigfunnia from the evil monster “Exponential
Asymptotic,” the king has given you the opportunity to earn a big reward. Behind the castle there
is a maze, and along each corridor of the maze there is a bag of gold coins. The amount of gold
in each bag varies. You will be given the opportunity to walk through the maze, picking up bags
of gold. You may enter only through the door marked “ENTER” and exit through the door
marked “EXIT.” (These are distinct doors.) While in the maze you may not retrace your steps.
Each corridor of the maze has an arrow painted on the wall. You may only go down the corridor
in the direction of the arrow. There is no way to traverse a “loop” in the maze. You will receive a
map of the maze, including the amount of gold in and the direction of each corridor. Describe
and analyze an efficient algorithm to help you pick up the most gold in this maze while
traversing a path from the start to the finish.
Solution
#include
using namespace std;
// Returns count of possible paths to reach cell at row number m and column
// number n from the topmost leftmost cell (cell at 1, 1)
int numberOfPaths(int m, int n)
{
// Create a 2D table to store results of subproblems
int count[m][n];
// Count of paths to reach any cell in first column is 1
for (int i = 0; i < m; i++)
count[i][0] = 1;
// Count of paths to reach any cell in first column is 1
for (int j = 0; j < n; j++)
count[0][j] = 1;
// Calculate count of paths for other cells in bottom-up manner using
// the recursive solution
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
// By uncommenting the last part the code calculatest he total
// possible paths if the diagonal Movements are allowed
count[i][j] = count[i-1][j] + count[i][j-1]; //+ count[i-1][j-1];
}
return count[m-1][n-1];
}
#include
using namespace std;
// Returns count of possible paths to reach cell at row number m and column
// number n from the topmost leftmost cell (cell at 1, 1)
int numberOfPaths(int m, int n)
{
// Create a 2D table to store results of subproblems
int count[m][n];
// Count of paths to reach any cell in first column is 1
for (int i = 0; i < m; i++)
count[i][0] = 1;
// Count of paths to reach any cell in first column is 1
for (int j = 0; j < n; j++)
count[0][j] = 1;
// Calculate count of paths for other cells in bottom-up manner using
// the recursive solution
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
// By uncommenting the last part the code calculatest he total
// possible paths if the diagonal Movements are allowed
count[i][j] = count[i-1][j] + count[i][j-1]; //+ count[i-1][j-1];
}
return count[m-1][n-1];
}

More Related Content

More from arihantcomputersddn

solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
arihantcomputersddn
 
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
arihantcomputersddn
 
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdfProblem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
arihantcomputersddn
 
please read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdfplease read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdf
arihantcomputersddn
 
Answer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdfAnswer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdf
arihantcomputersddn
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
arihantcomputersddn
 

More from arihantcomputersddn (20)

Which of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdfWhich of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdf
 
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdfWhich of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
 
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdfWhere are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
 
Talks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdfTalks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdf
 
What kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdfWhat kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdf
 
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdfWhen H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
 
The standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdfThe standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdf
 
The difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdfThe difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdf
 
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
 
Question 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdfQuestion 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdf
 
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
 
QUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdfQUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdf
 
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdfProblem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
 
please read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdfplease read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdf
 
Name 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdfName 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdf
 
Answer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdfAnswer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdf
 
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdfIn how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
 
In a certain year, 86 of all Caucasians in the U.S., 76 of all Afr.pdf
In a certain year, 86 of all Caucasians in the U.S., 76 of all Afr.pdfIn a certain year, 86 of all Caucasians in the U.S., 76 of all Afr.pdf
In a certain year, 86 of all Caucasians in the U.S., 76 of all Afr.pdf
 
Hosts A through J have been connected to a switch for some time, wit.pdf
Hosts A through J have been connected to a switch for some time, wit.pdfHosts A through J have been connected to a switch for some time, wit.pdf
Hosts A through J have been connected to a switch for some time, wit.pdf
 
I have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdfI have code written for this problem but I am struggling finishing i.pdf
I have code written for this problem but I am struggling finishing i.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf

  • 1. As your reward for saving the Kingdom of Bigfunnia from the evil monster “Exponential Asymptotic,” the king has given you the opportunity to earn a big reward. Behind the castle there is a maze, and along each corridor of the maze there is a bag of gold coins. The amount of gold in each bag varies. You will be given the opportunity to walk through the maze, picking up bags of gold. You may enter only through the door marked “ENTER” and exit through the door marked “EXIT.” (These are distinct doors.) While in the maze you may not retrace your steps. Each corridor of the maze has an arrow painted on the wall. You may only go down the corridor in the direction of the arrow. There is no way to traverse a “loop” in the maze. You will receive a map of the maze, including the amount of gold in and the direction of each corridor. Describe and analyze an efficient algorithm to help you pick up the most gold in this maze while traversing a path from the start to the finish. Solution #include using namespace std; // Returns count of possible paths to reach cell at row number m and column // number n from the topmost leftmost cell (cell at 1, 1) int numberOfPaths(int m, int n) { // Create a 2D table to store results of subproblems int count[m][n]; // Count of paths to reach any cell in first column is 1 for (int i = 0; i < m; i++) count[i][0] = 1; // Count of paths to reach any cell in first column is 1 for (int j = 0; j < n; j++) count[0][j] = 1; // Calculate count of paths for other cells in bottom-up manner using // the recursive solution for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) // By uncommenting the last part the code calculatest he total // possible paths if the diagonal Movements are allowed
  • 2. count[i][j] = count[i-1][j] + count[i][j-1]; //+ count[i-1][j-1]; } return count[m-1][n-1]; } #include using namespace std; // Returns count of possible paths to reach cell at row number m and column // number n from the topmost leftmost cell (cell at 1, 1) int numberOfPaths(int m, int n) { // Create a 2D table to store results of subproblems int count[m][n]; // Count of paths to reach any cell in first column is 1 for (int i = 0; i < m; i++) count[i][0] = 1; // Count of paths to reach any cell in first column is 1 for (int j = 0; j < n; j++) count[0][j] = 1; // Calculate count of paths for other cells in bottom-up manner using // the recursive solution for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) // By uncommenting the last part the code calculatest he total // possible paths if the diagonal Movements are allowed count[i][j] = count[i-1][j] + count[i][j-1]; //+ count[i-1][j-1]; } return count[m-1][n-1]; }