P(n,x)实现

问题:【动态规划实现】

以下函数的功能是用递归的方法计算x的n阶勒让德多项式的值。已有调用语句p(n,x)。编写函数实现功能。递归公式如下:

————————————————————————————————————————————————————————————

View Code
 1 #include <iostream>
2 using namespace std;
3
4 double f[10000];
5
6 void p(int n ,int x)
7 {
8 for(int i=2;i<=n;i++)
9 {
10 f[i] = ((2*i-1)*x*f[i-1] - (i-1)*f[i-2])/2;
11 }
12 }
13 void main()
14 {
15 f[0] = 0;
16 f[1] = 1;
17 int n,x;
18 cin >> n >> x;
19 p(n,x);
20
21 cout << f[n] << endl;
22
23 }

测试:

10 1
384398
请按任意键继续. . .

原文地址:https://www.cnblogs.com/xuxu8511/p/2425423.html