|We need to get corn to the starving victims of a disaster. We will load up a
truck and choose a route to the disaster site. But the roads are bad, and
the more we put on the truck, the greater is the probability that we will
get stuck somewhere on our route and be unable to deliver the corn.
The probability of successfully completing any segment of our route is the
product of the goodness of the road segment (a value between 0.0 and 1.0 inclusive)
and the lightness of our load, defined to be 1.0 - b*load where b is a
specified constant and load is the amount of corn we carry. Loads that would
yield a negative lightness value are not possible.
The road segments go between villages. They are described by a String roads.
The k-th element of roads lists the goodness of the road segments from village k to each of
the villages in order. The goodness from village k to village j may be different
from the goodness from village j to village k. (The goodness from village k to village k
is always 1.) A goodness of 0 indicates that
there is no useable road segment. Village 0 is where the truck and corn are located,
while village 1 is the site of the disaster.
Create a class Disaster that contains a method expected. The method is
given b (the coefficient in the lightness calculation) and roads. It returns
the expected amount of corn that can be delivered if we choose the best load