82. 猴子爬山
題目描述
一天一只頑猴想去從山腳爬到山頂,途中經過一個有個N個臺階的階梯,但是這猴子有一個習慣: 每一次只能跳1步或跳3步,試問猴子通過這個階梯有多少種不同的跳躍方式?
解答要求時間限制:1000ms, 內存限制:100MB
輸入
輸入只有一個整數N(0<N<=50)此階梯有多少個階梯
輸出
輸出有多少種跳躍方式(解決方案數)
樣例
提示
思路:動態規劃,數組,遞歸
代碼:
// we have defined the necessary header files here for this problem. // If additional header files are needed in your program, please import here. int main() { int A[55] = {0}; int N; A[1] = 1; A[2] = 1; A[3] = 2; for(int i = 4;i<51;i++) { A[i] = A[i-1]+A[i-3]; } while(scanf("%d",&N)!=EOF) { printf("%d\n",A[N]); } // please define the C input here. For example: int n; scanf("%d",&n); // please finish the function body here. // please define the C output here. For example: printf("%d\n",a); return 0; }
以大多數人努力程度之低,根本輪不到去拼天賦~

浙公網安備 33010602011771號