典型 斐波那契数列
动态规划 一步搞定
#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")