递归简论

/**f(x)=2f(x-1)+x^2;f(0)=0;**/
#include <stdio.h>
#include <stdlib.h>
int f(unsigned int x)
{
    if(x==0)
        return 0;//处理基准情况
    //基准情形:你必须总要有某些基准的情形,它们不用递归就能求解
    else
        return 2*f(x-1)+x*x;
    //不断推进:对于那些需要递归求解的情形,递归调用必须总能够朝着产生基准情形的方向推进
}
int main()
{
    unsigned int n;
    while(~scanf("%d",&n))
    {
        printf("%u
",f(n));
    }
    return 0;
}
原文地址:https://www.cnblogs.com/webmen/p/5739707.html