climb专题

UVA 12170 Easy Climb(dp+单调队列优化)

题意:给出一个序列,首尾不可改变,要求你使序列满足相邻2个|x_i - x_(i-1)| <=d,改变的代价就是两数相减绝对值,问最小代价。 分析: 区间dp类问题,根据题意,我们需要修改2到n-1之间的一些h的值,使得相邻2个h值差的绝对值不超过d。因为可以修改的数是一个实数,无法一一枚举,因此需要仔细对问题进行分析。 首先,考虑只有3个值的情况:h1, h2, h3。那么根据题意,h2应

LeetCode Climb Stairs

题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 题意: 就是上楼梯的方式的种数。每次只能用1

climb_stairs爬楼梯 递归C++

#include <iostream>using namespace std;int N;int stairs(int n){//递归出口1if( n < 0)return 0;//递归出口2if( n == 1)return 1;return stairs(n-1) + stairs(n-2);}int main(){while(cin>>N){cout<<stairs(N)<<en