Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE SOLVE IN PYTHON USING DYNAMIC PROGRAMMING Write a program that helps Beata find the ideal mushroom picking spot. Beata lives in linear land: The
PLEASE SOLVE IN PYTHON USING DYNAMIC PROGRAMMING
Write a program that helps Beata find the ideal mushroom picking "spot". Beata lives in "linear land": The mushroom picking spots in this place are ordered along a line. For each spot we have information about how many mushrooms can be found there. The ideal mushroom picking spot is one where the total number of mushrooms in closeby neighboring spots reaches a critical number m. Input The input has two lines, the first containing the critical number m, which is a nonnegative integer, the second containing the number of mushrooms at successive spots (nonnegative integers), separated by spaces. Output For each spot, print the number of spots that has to be visited to the right of that spot (including the spot where one starts) so that the number of mushrooms at the visited spots reaches the critical number of mushrooms that Beata has to collect (equality is also fine). If visiting all remaining spots is insufficient, then print 0. If the critical number is zero, print 1 for each spot. Samples Input 4 0 1 2 1 3 4 0 1 0 1 0 1 1 Output 4 3 3 2 2 1 7 6 0 0 0 0 0 Explanation: While at the first stop, Beata has to visit the next 3 spots to collect 4 mushrooms (visiting all these spots, she can pick exactly 4 mushrooms). So, together with the spot she started at, she has to visit 4 spots. Hence, the first number to print is 4. For the second spot, she has to visit the same spots, but now she already starts on the second spot, so the output for this spot is 3. At the third spot, if she visits two additional spots to the right of this spot she can collect 6 mushrooms (but visiting one additional spot is insufficient). This goes on. Now, at the end, when Beata starts from any of the last 5 spots, visiting all the spots to the right of the chosen spot is insufficient to collect 4 mushrooms. Thus, the output for these spots is zero. Input 10 5 4 3 2 1 Output 3 4 0 0 0Step 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