#include <stdio.h>
int buf[1000] = {0, 1, 1};
typedef struct
{
int a;
int b;
}intPair;
intPair devideIndex(int index)
{
intPair temp;
if (index & 1)
{
temp.a = index / 2;
temp.b = index / 2 + 1;
return temp;
}
else
{
temp.a = index / 2;
temp.b = index / 2;
return temp;
}
}
int Fibonacci(int n)
{
intPair p;
if (buf[n])
return buf[n];
p = devideIndex(n);
return buf[n] = Fibonacci(p.a) * Fibonacci(p.b - 1) + Fibonacci(p.a + 1) * Fibonacci(p.b);
}
int main()
{
int i;
for (i = 1; i <= 20; ++i)
printf("%d\n", Fibonacci(i));
system("pause");
return 0;
}
以上
int buf[1000] = {0, 1, 1};
typedef struct
{
int a;
int b;
}intPair;
intPair devideIndex(int index)
{
intPair temp;
if (index & 1)
{
temp.a = index / 2;
temp.b = index / 2 + 1;
return temp;
}
else
{
temp.a = index / 2;
temp.b = index / 2;
return temp;
}
}
int Fibonacci(int n)
{
intPair p;
if (buf[n])
return buf[n];
p = devideIndex(n);
return buf[n] = Fibonacci(p.a) * Fibonacci(p.b - 1) + Fibonacci(p.a + 1) * Fibonacci(p.b);
}
int main()
{
int i;
for (i = 1; i <= 20; ++i)
printf("%d\n", Fibonacci(i));
system("pause");
return 0;
}
以上