subject

You decide to take a break from computer science, and instead go into environmental engineering. Luckily, your computer science skills will come in handy! Your first job is to deal with modeling the water run-off – or drainage – in a basin area. Given a representation of the area to model, your task is to determine how far the water will flow.
The land will be represented by topographical map, which is a two-dimensional square grid of elevations.
Each grid will have n rows and n columns. Each grid location – or grid cell – will have a non-negative
integer height elevation.
The input files will be formatted such that the first line contains the dimensionality of the grid, and the remaining lines will represent the values in the grid. Columns are separated by a space, rows separated by newlines.
Your task is to figure out the longest sequence of grid locations that water can flow between. Water will flow from a higher elevation to a lower elevation. For the purposes of this problem, water will never flow from a given elevation to the same elevation, nor will it flow uphill. Furthermore, water can only flow from one grid cell to an adjacent cell (adjacent cells are above, below, left, and right; not diagonal!).
As an example, consider the following 5x5 grid (this is sample. txt in this exercise’s zip file). Note that the input in this example is justified to help illustrate the grid; there will only be one space between heights in the actual input. Recall that the first line indicates the grid’s size.
5
66 78 41 3 77
4 90 41 8 68
12 11 29 24 53
0 51 58 9 28
97 99 96 58 92
There are many such valid drainage paths in this grid. One starts in the second cell of the second row, and
flows from 90-78-41-3. Note that 90-41-41-3 is not a valid drainage flow, as water is not always flowing
downhill (41-41 is not downhill). The longest drainage path in this example is of length 7, and flows from
the 99 in the bottom row to the 3 in the top row; the full path is 99-96-58-29-24-8-3.
You may solve this problem using top-down Dynamic Programming or using bottom-up Dynamic
Programming. We think that top-down will be much easier here, but you do you. Certainly a brute-force
solution’s running time will be too long. Likely the best way to check that your algorithm is properly
Dynamic Programming is to comment out the portion where you look up solutions to subproblems. If
the algorithm gets substantially slower, then you are (or rather were) using DP!
You should be able to obtain an algorithm that runs in n 2 time, but your algorithm definitely should not
run in ω(n3) time. You do not need to justify the running time of your algorithm.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:00
What is a society that has moved to the internet rather than relying on physical media called
Answers: 2
question
Computers and Technology, 22.06.2019 18:30
List the five on-board vehicle subsystems
Answers: 1
question
Computers and Technology, 23.06.2019 07:30
What is the original authority for copyright laws
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Donnie does not have powerpoint. which method would be best for elana to save and share her presentation as is? a pdf a doc an rtf a ppt
Answers: 3
You know the right answer?
You decide to take a break from computer science, and instead go into environmental engineering. L...
Questions
question
Law, 06.09.2021 01:50
Questions on the website: 13722360