#include "stdafx.h"
#include <string>
using namespace std;
int f(int a[],int n)
{
a[0] = 0;
a[1] = 1;
for (int i = 2; i <= n; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
return a[n];
}
int _tmain(int argc, _TCHAR* argv[])
{
int n = 10;//需要求解的数
int* a = (int*)malloc((n + 1)*sizeof(int));
for (int i = 0; i < n + 1; i++)
{
a[i] = -1;
}
printf("%d\n子问题的解", f(a, n));
for (int i = 0; i < n + 1; i++)
{
printf("%d ", a[i]);
}
getchar();
return 0;
}
自底向上的解决方案