标签:blog http io strong for 2014 amp log
#include <stdio.h>
#define MAX 50+1
int a[MAX];
int fib(int n)
{
if (a[n]==-1) return a[n]=fib(n-1)+fib(n-2);
else return a[n];
}
int main( )
{
int i,n;
for(i=1; i<MAX; i++)
a[i]=-1;
a[0]=a[1]=1;
scanf("%d",&n);
printf("%d\n" ,fib( n ) );
}
*******************************************************************
#include <stdio.h>
#define MAX 50+1
int a[MAX];
int fib(int n)
{
if (a[n]!=-1) a[0]=a[1]=1;
if (a[n]==-1) return a[n]=fib(n-1)+fib(n-2);
else return a[n];
}
int main( )
{ int i,n;
for(i=1; i<MAX; i++)
a[i]=-1;
scanf("%d",&n);
printf("%d\n" ,fib( n ) );
}
ppt Fibonacii数列的第n项------记忆式搜索,布布扣,bubuko.com
ppt Fibonacii数列的第n项------记忆式搜索
标签:blog http io strong for 2014 amp log
原文地址:http://www.cnblogs.com/2014acm/p/3907879.html