T1165:Hermite多项式

【题目描述】

用递归的方法求Hermite多项式的值

对给定的x和正整数n,求多项式的值。

【输入】

给定的n和正整数x

【输出】

多项式的值。

【输入样例】

1 2

【输出样例】

4.00

AC代码:

#include<iostream>
#include<iomanip>
using namespace std;
double her(int n, int x){
	if(n == 0)	return 1;
	else if(n == 1)	return 2 * x;
	else if(n > 1)	return 2 * x * her(n - 1, x) - 2 * (n - 1) * her(n - 2, x);
}
int main(){
	int n, m;
	cin >> n >> m;
	cout << fixed << setprecision(2) << her(n, m);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42522886/article/details/88375970