感谢http://hzwer.com/2860.html
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10050 using namespace std; int n; double f[maxn],g[maxn]; int main() { scanf("%d",&n); for (int i=n-1;i>=0;i--) f[i]=f[i+1]+(double)n/(n-i); for (int i=n-1;i>=0;i--) { double ret=1+(double)i/n*f[i]+(double)(n-i)/n*(g[i+1]+f[i+1]); g[i]=ret*n/(n-i); } printf("%.2lf\n",g[0]); return 0; }