Question
Write a C++ program called coin_collection.cpp to collect maximum number of coins on an n x m board with inaccessible cells . The program should
Write a C++ program called coin_collection.cpp to collect maximum number of coins on an n x m board with inaccessible cells.
The program should ask a user for a text filename to read a 2-D array of a sequence of numbers. In the array, 1 indicates that theres a coin on the cell, while 0 means no coin. A cell with the number 2 indicates that the cell is not accessible. The program should display maximum possible coins and path to collect it. If you have more than one path, you only need to display one. For this program, you can assume that the board size is less than or equal to 25 x 25.
This is a sample run of the program:
$ g++ -o coin_collection coin_collection.cpp
$ ./coin_collection
Enter a file name: ./t1.txt
Max coins: 3
Path:(1,1)->(2,1)->(2,2)->(3,2)->(3,3)->(4,3)->(4,4)
For the sample run, t1.txt has the following context:
|
The first line (= 4 and 4 in the example) indicates the numbers of rows and columns in the file. One blank space is used to delimiter the data. Note that theres no blank space at the end of each line. In the sample execution, the starting indexes of the path are 1, not 0.
This is another sample run.
$ g++ -o coin_collection coin_collection.cpp
$ ./coin_collection
Enter a file name: ./t2.txt
Max coins: 1
Path:(1,1)->(1,2)->(1,3)->(1,4)->(2,4)
For the sample run, t2.txt has the following context:
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started