题解 | #N阶楼梯上楼问题#
N阶楼梯上楼问题
https://www.nowcoder.com/practice/c978e3375b404d598f1808e4f89ac551
#include <iostream> #include <algorithm> using namespace std; const int N =100; int f[N]; int n; int main() { cin >>n; f[1] = 1; f[2] = 2; if(n == 1||n==2) cout<< f[n]; else{ for(int i=3;i<=n;i++) f[i] = f[i-1]+f[i-2]; cout << f[n]; } } // 64 位输出请用 printf("%lld")