原理同上台阶问题
#include <iostream> #include <cstdio> #include <vector> #include <string> #include <set> using namespace std; int countcoke(int N) { vector<int> dp(N + 1); dp[1] = 1; dp[2] = 2; for (int i = 3; i <= N; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[N]; } int main() { int N; scanf("%d", &N); printf("%d", countcoke(N)); return 0; }