Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with writing a ruccurence I am runnin ito errors with the code Question 2 : Bad sizes Mr E has noticed something quite

Please help with writing a ruccurence I am runnin ito errors with the code Question 2: Bad sizes
Mr E has noticed something quite strange: Any bean stalk whose length leaves a remainder of 2 when divided by 7 dies over night.
He demands you change your algorithm to avoid these 'dead lengths.' You think it might just be his cat digging around in the pots late at night, but you don't wish to argue.
2(A) Write a recurrence.
Write a recurrence minGoodDrops (j,n) that represents the minimum number of drops of fertilizer necessary to grow a bean stalk from j inches to n inches, avoiding any intermediate stage of length k when k mod 7=2.
[13]:dp =[float('inf')]*(n +1)for i in range(j, n +1): for d in range(1, n - i +1): if next_length = n and next_length %7!=2:return dp[n][14]:print(minGoodDrops(1,9)) # should be 2
print(minGoodDrops(1,13)) # should be 2
print(minGoodDrops(1,19)) # should be 4
print(minGoodDrops(1,34)) # should be 5
print(minGoodDrops(1,43)) # should be 5
print(minGoodDrops(1,55)) # should be 6
inf
1
12(B) Memoize the recurrence in 2(A)
[10]: def minGoodDrops_Memoize(n): # j is assumed to be 1
return 100
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

=+4. What might explain any differences that you identify?

Answered: 1 week ago

Question

=+2. Is there a strong collective bargaining culture in evidence?

Answered: 1 week ago