Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

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_2

Step: 3

blur-text-image_3

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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions