牛客 KY96 Fibonacci

牛客 KY96 Fibonacci

题目描述

The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55…} are defined by the recurrence: F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2 Write a program to calculate the Fibonacci Numbers.
输入:n,0-30之间
输出:fibonacci数
传送门:牛客 KY96 Fibonacci

解法

#include "stdio.h"
#include "vector"
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int f[50];
    f[0]=0;f[1]=1;f[2]=1;f[3]=2;
    for(int i=4;i<=30;i++){
        f[i]=f[i-1]+f[i-2];
    }
    printf("%d\n",f[n]);
    return 0;
}

你可能感兴趣的:(动态规划,动态规划,c语言)