【题目描述】
用递归的方法求Hermite多项式的值
hn(x)=⎧⎩⎨⎪⎪12x2xhn−1(x)−2(n−1)hn−2(x)n=0n=1n>1hn(x)={1n=02xn=12xhn−1(x)−2(n−1)hn−2(x)n>1
对给定的xx和正整数nn,求多项式的值。
【输入】
给定的nn和正整数xx。
【输出】
多项式的值。
【输入样例】
1 2
【输出样例】
4.00
注意下这个表达式的写法,与n有关
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int n,x;
double f(int n,int x)
{
if(n==0)
return 1;
else if(n==1)
return 2*x;
else
return 2*x*f(n-1,x)-2*(n-1)*f(n-2,x);
}
int main()
{
//itn n,x;
cin>>n>>x;
cout<<fixed;
cout<<setprecision(2);
cout<<f(n,x)<<endl;
return 0;
}