Similar to 14129- Climbing Stairs part 1, each time you can either climb 1
or 2
steps.
However, in this problem, you are given an integer array cost
where cost[i]
is the cost of ith
step on a staircase.
After you pay the cost, you can either climb one or two steps.
You asked to calculate the minimum cost to reach Nth stairs.
Note that you can start from index 0 or index 1 in this problem.
For example,
If cost = [1,100,1,1,1,100,1,1,100,1],
You will start at index 0. - Pay 1 and climb two steps to reach index 2. - Pay 1 and climb two steps to reach index 4. - Pay 1 and climb two steps to reach index 6. - Pay 1 and climb one step to reach index 7. - Pay 1 and climb two steps to reach index 9. - Pay 1 and climb one step to reach the top. The total cost is 6.
There are T Ns in this problem.
The first line is an integer T, the number of testcases.
The second line is an integer C, the number of costs.
The third line are C integers costs, where (1<= the value of the cost <= 999).
And the following T lines are the heights of the stairs.
For test case 1 on OJ: (1<=T<=5) and (1<=C<=10).
For test case 2 on OJ: (1<=T<=100) and (1<=C<=100).
T solutions ended with a newline character.