题解 | #贪吃牛#
贪吃牛
https://www.nowcoder.com/practice/ae6261c872724fda8913b0377e85f6ab
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @return int整型 */ int eatGrass(int n) { // write code here int* dp = new int[n + 1]; memset(dp,0,sizeof(int) * (n + 1)); dp[0] = 1; dp[1] = 1; for (int i = 2;i <= n;++i) { dp[i] = dp[i - 1] + dp[i - 2]; } return dp[n]; } };