Question: 3. (12 pts) Consider a staircase with n steps. Each step i has some non-negative cost, cost[i]. Steps are indexed from 0 to n-1. You

 3. (12 pts) Consider a staircase with n steps. Each step

3. (12 pts) Consider a staircase with n steps. Each step i has some non-negative cost, cost[i]. Steps are indexed from 0 to n-1. You want to climb these stairs. Once you pay the cost, you can either climb one or two steps. Design a dynamic programming algorithm to find the minimum cost to reach the top of the floor. You can either start from the step O or step 1. Some examples are as follows: n basamakl bir merdiven dnn. Her i. basaman negatif olmayan bir maliyeti vardr, cost[i]. Basamaklar O'dan n-1'e kadar indekslenir. Bu merdivenleri trmanmak istiyorsun. creti dedikten sonra bir veya iki basamak kabilirsiniz. En st kata ulamann minimum maliyetini bulmak iin dinamik bir programlama algoritmasi tasarlayn. 0. basamaktan veya 1. basamaktan balayabilirsiniz. Baz rnekler aadaki gibidir: Example 1: input: cost = {10,15,20} 1: Output = 15 (minimum cost is obtained when you start on cost[1], pay that cost and go to top) Example 2: input: cost = {1,100,1,1,1,100,1,1,100,1} Output = 6 (minimum cost is obtained when you start on cost[0], and only step on 1s, skipping cost[3]) Hint: Define f[i] as the final cost to climb to the top from step i. Find a recurrence relation for f[i] pucu: f[i]'yi i. basamaktan en tepeye trmanmann son maliyeti olarak tanmlayn. f[i] iin bir yineleme ilikisi bulun. =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!