题解 | #跳台阶扩展问题#
跳台阶扩展问题
https://www.nowcoder.com/practice/953b74ca5c4d44bb91f39ac4ddea0fee
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <map> #include <queue> #include <cmath> using namespace std; int arr[23]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 1; i < 23; i++) { arr[i] = 0; if (i == 1) { arr[i] = 1; } else if (i == 2) { arr[i] = 2; } else { for(int j = 1; j < i; j++){ arr[i] += arr[j]; //s[i] = s[i - 1] + s[i - 2] +....+ s[0] } arr[i] += 1; } } printf("%d\n", arr[n]); } }