Question: You are climbing a tower which is n steps high from the ground. To climb the tower from ground to the top, you have

You are climbing a tower which is n steps high from the 

You are climbing a tower which is n steps high from the ground. To climb the tower from ground to the top, you have to pay and cost, is the cost you have to pay when you climb from step i. Once cost, is paid, you can choose 1 or 2 steps to take forward. Initially, you can start from either step 0 or step 1. If you are aware of the price list at each step, please design and implement a program returning the minimal cost to arrive at the top of the tower, which is step n. For example: n=9 cost0=1 cost6=1 cost1=100 cost7=1 cost2=1 cost8=80 cost3=1 cost9=1 cost4=1 cost5=90 The minimal cost is 6. Solution: Start from step 0; Pay 1, and take 2 steps, reaches step2; Pay 1, and take 2 steps, reaches step4; Pay 1, and take 2 steps, reaches step; Pay 1, and take 1 step, reaches step7; Pay 1, and take 2 steps, reaches step9; Pay 1, and take 1 step, reaches the top. Total cost: 6

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 Programming Questions!