这个应该放在前面上的,只不过一cha忘了,今天我们把递归学习完。
递归和递推名字很像,很多递归的入门题都可以用递推AC,但是递归也是一种很多问题的解法,是必不可少的一个知识点,话不多说,直接如题。
【基础问题】
n的阶乘可表示为 n! =123*……(n-1)n,1! = 1。例如3的阶乘3!=123 =6。输入一个整数n(n<=15);
输出n的阶乘。
解题思路:
设:n的阶乘为f(n),观察可知f(n) = n * f(n-1)
我们用递推先来解一下:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <list>
#include <limits.h>
using namespace std;
long long f[N];
int main