【问题描述】
用递归的方法求Hermite多项式的值。
对给定的x和正整数n,求多项式的值。
【输入格式】:
给定的n和正整数x。
【输出格式】:
多项式的值。
【输入样例】:
1 2
【输出样例】:
4.00
【参考程序】
#include <cstdio>
#include <iostream>
using namespace std;
double h(int n, int x) {
if (n == 0) {
return 1;
} else if (n == 1) {
return 2 * x;
} else {
return 2*x*h(n-1,x) - 2*(n-1)*h(n-2,x);
}
}
int main() {
int n, x;
cin >> n >> x;
printf("%.2lf", h(n,x)); // 输出h(n,x)的值,精确到小数点后2位
return 0;
}
这篇博客介绍如何使用递归方法计算Hermite多项式的值,详细说明了输入和输出格式,并给出了一个样例及其对应的输出结果。
212

被折叠的 条评论
为什么被折叠?



