题解 | #跳台阶扩展问题#
跳台阶扩展问题
https://www.nowcoder.com/practice/953b74ca5c4d44bb91f39ac4ddea0fee
f(n)=f(n−1)+f(n−2)+⋯+f(1)+f(0)
f(n - 1) = f(n−2)+⋯+f(1)+f(0)
f(n) = 2 * f(n - 1)
#include <iostream> using namespace std; const int N = 50; int f[N]; int main() { int n; cin >> n; f[0] = 1; for(int i = 1; i <= n; i ++){ f[i] = f[i - 1] * 2; } cout << f[n - 1] << endl; return 0; }