题目链接:https://www.luogu.com.cn/problem/P4550
AC代码:
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 const int N=10005; 5 double f[N],g[N]; 6 int n; 7 int main(){ 8 scanf("%d",&n); 9 for(int i=n-1;i>=0;i--){ 10 f[i]=f[i+1]+n*1.0/(n-i); 11 g[i]=1.0*i/(n-i)*(f[i]+1)+g[i+1]+f[i+1]+1; 12 } 13 printf("%.2lf ",g[0]); 14 return 0; 15 }