https://leetcode.com/problems/min-cost-climbing-stairs/description/
题目:求到达目标位置的最小耗费
思路:动态规划( cost[x]=min(cost[x-1]+cost[x],cost[x-2]+cost[x]))
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
for(int x=2;x<cost.size();x++){
cost[x]=min(cost[x-1]+cost[x],cost[x-2]+cost[x]);
}
return min(cost[cost.size()-1],cost[cost.size()-2]);
}
};