题解 | #吃糖果#
吃糖果
http://www.nowcoder.com/practice/72015680c32b449899e81f1470836097
利用动态规划实现,斐波那契数列:1 1 2 3 5 8 13 .....
#include <math.h>
#include <string.h>
#include<stdlib.h>
int main()
{
int n;
while (scanf("%d",&n) != EOF){
int first = 1,second = 1;
int third;
for ( int i = 2;i <= n;i++ ){
third = first + second;
first = second;
second = third;
}
printf("%d\n",second);
}
}