Truffle hunting in France is a big business. When one searches for truffles, one
ID: 3606005 • Letter: T
Question
Truffle hunting in France is a big business. When one searches for truffles, one conceptually organizes the countryside as a grid each of which contains some number of truffles which differs at each square of the grid. By tradition, truffle hunters are permitted only one path through the grid, starting at the upper left and terminating at the lower right. That is, one may pick up all the truffles in a given square of the grid but one may only traverse (1) to the right or (2) down, never (3) diagonally or (4) left or (5) up. Given a map for a given grid that shows, for each pair of locations in the grid, how many truffles are to be found in going from one to the other, there is at least one optimal path from the upper left to the lower right, the traversal of which will maximize the total number of truffles one can retrieve. You will write a program to solve this problem. When executed, you program will prompt for a filename understood to be in the same subdirectory as the executing program. The output will be (1) a sequence of grid positions traversed in a path that pair that maximizes the total number of truffles harvested, together with (2) the total number of truffles collectable along that path. The input file will represent the number of truffles to be found along the path from one grid and another. The following grid, in which the number of truffles is par The input file will simply consist of positive integers, underline scores, embraced within parentheses, thus: (3 1) (2 0) (4 2) (0 4) (_ 3) (3 4) (2 6) (4 5) (2 2) (_ 1) (0 4) (7 4) (3 5) (4 2) (_ 1) (3 5) (3 6) (0 8) (2 5) (_ 3) (1 _) (3 _) (2 _) (2 _) (_ _) The file is to be interpreted in this way: 1. The first pair in the file represents the upper right-hand corner of the grid. The first number in a pair tells you how many truffles can be retrieved by the next square to the right. The second number tells you how many truffles can be retrieved by going to the grid location immediately below. 2. An underscore in the left position of a pair tells you that you cannot go further to the right. 3. An underscore in the right position of a pair tells you that you cannot traverse further down. write it in java or racket.
Explanation / Answer
consider
R1 = Drawing a raspberry truffles from first gift box, M1 = Drawing a mint truffles from first gift box
R2 = Drawing a raspberry truffles from second gift box, M1 = Drawing a mint truffles from second gift box
P(R1) = 4/9 , P(M1) = 5/9 , P(R2) = 3/5 , P(M2) = 2/5
P(both truffles are of the same flavour) =[ P(Raspberry truffle from first gift box) and P(Raspberry truffle from second gift box)] or[ P(mint truffle from first gift box) and P(mint truffle from second gift box)]
=4/9 * 3/5 + 5/9 * 2/5
= 0.488888889
P(both truffles are of the different flavour) = 1 - P(both truffles are of the same flavour)
= 0.511111111111
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.