Task 06 (Flood Fill): Dora is leaving the country. Before leaving the country, as a token of gesture, Dora gifted you with a map of the jungle "Jumanji". The map is very interesting. The map is a 2D grid. Some of those cells are occupied by diamonds and obstacles. [See the Sample input for better understanding.] Now, you are on a journey to Jumanji in search of Diamonds. However, since the jungle is full of ferocious creatures, you can't collect all the diamonds. You will choose only one start position such that you collect the maximum amount of diamonds. Please note that you can not move to any cell which contains obstacles. Input The first line contains two integers R and H (1 <= R, H <= 100) - the number of rows and columns respectively in the grid. The next R line will contain H characters. Each character represents the status of a cell as follows. 1).': Empty Cell You can move here. 2) 'D': Cell with a Diamond → If you move to the cell containing 'D', you will collect that Diamond. 3) '#': Cell with an obstacle - You can't move to this cell. Output Print a single integer that denotes the maximum amount of Diamonds you can collect. [The diamonds are coloured red to demonstrate which diamonds have been collected.] Sample Input 1 43 ..D D.. .D. ##. Sample Input 2 10 7 ...#..D ...#D.. D..#.D. Sample Output 1 3 Sample Output 2 11

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
Please use python and python file i/o to solve the problem. Create an input file input6_1.txt as shown below, solve the problem and print the output to output6_1.txt file as shown in the question.
Task 06 (Flood Fill):
Dora is leaving the country. Before leaving the country, as a
token of gesture, Dora gifted you with a map of the jungle
"Jumanji".
The map is very interesting. The map is a 2D grid. Some of those
cells are occupied by diamonds and obstacles. [See the Sample
input for better understanding. ]
Now, you are on a journey to Jumanji in search of Diamonds.
However, since the jungle is full of ferocious creatures, you
can't collect all the diamonds. You will choose only one start
position such that you collect the maximum amount of diamonds.
Please note that you can not move to any cell which contains
obstacles.
Input
The first line contains two integers R and H (1 <= R, H <= 100)
- the number of rows and columns respectively in the grid.
The next R line will contain H characters. Each character
represents the status of a cell as follows.
1). Empty Cell You can move here.
2) 'D': Cell with a Diamond → If you move to the cell
containing 'D', you will collect that Diamond.
3) '#': Cell with an obstacle → You can't move to this cell.
Output
Print a single integer that denotes the maximum amount of
Diamonds you can collect.
[The diamonds are coloured red to demonstrate which diamonds
have been collected.]
Sample Input 1
43
..D
D..
.D.
##.
Sample Input 2
10 7
...#..D
... #D..
D..#.D.
Sample Output 1
3
Sample Output 2
11
Transcribed Image Text:Task 06 (Flood Fill): Dora is leaving the country. Before leaving the country, as a token of gesture, Dora gifted you with a map of the jungle "Jumanji". The map is very interesting. The map is a 2D grid. Some of those cells are occupied by diamonds and obstacles. [See the Sample input for better understanding. ] Now, you are on a journey to Jumanji in search of Diamonds. However, since the jungle is full of ferocious creatures, you can't collect all the diamonds. You will choose only one start position such that you collect the maximum amount of diamonds. Please note that you can not move to any cell which contains obstacles. Input The first line contains two integers R and H (1 <= R, H <= 100) - the number of rows and columns respectively in the grid. The next R line will contain H characters. Each character represents the status of a cell as follows. 1). Empty Cell You can move here. 2) 'D': Cell with a Diamond → If you move to the cell containing 'D', you will collect that Diamond. 3) '#': Cell with an obstacle → You can't move to this cell. Output Print a single integer that denotes the maximum amount of Diamonds you can collect. [The diamonds are coloured red to demonstrate which diamonds have been collected.] Sample Input 1 43 ..D D.. .D. ##. Sample Input 2 10 7 ...#..D ... #D.. D..#.D. Sample Output 1 3 Sample Output 2 11
×
43
..D
D..
.D.
##.
input6_1.txt
Transcribed Image Text:× 43 ..D D.. .D. ##. input6_1.txt
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Web Page
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