Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
77192 刘浩宇 吃巧克力 C++ Accepted 1 MS 272 KB 534 2024-06-08 16:02:58

Tests(10/10):


Code:

#include <iostream> using namespace std; int countWaysToEatChocolates(int N) { int dp[20] = {0}; dp[0] = 1; dp[1] = 1; for (int i = 2; i <= N; ++i) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[N]; } int main() { int N; cin >> N; if (N >= 0 && N <= 20) { int ways = countWaysToEatChocolates(N); cout << ways << endl; } else { cout << "输入的N不符合要求,请重新输入。" << endl; } return 0; }