标签:ios -- algorithm input names mat gre output detail
期望递推
一涉及到期望就超考智商的样子。
推荐题解:http://blog.csdn.net/braketbn/article/details/51024591
推了好久,卡在了最后二维化一维那步没看出来……蠢哭
虽然麻烦,不过代码很短,我喜欢
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 const int mxn=10010; 9 double f[mxn],g[mxn]; 10 int n; 11 int main(){ 12 int i,j; 13 scanf("%d",&n); 14 g[n]=f[n]=0; 15 for(i=n-1;i>=0;i--)g[i]=g[i+1]+n/(double)(n-i); 16 for(i=n-1;i>=0;i--)f[i]= (g[i]*i+n+(f[i+1]+g[i+1])*(n-i))/(double)(n-i); 17 printf("%.2f\n",f[0]); 18 return 0; 19 }
标签:ios -- algorithm input names mat gre output detail
原文地址:http://www.cnblogs.com/SilverNebula/p/6246967.html