1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include<bits/stdc++.h> #define RG register #define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout); #define clear(x, y) memset(x, y, sizeof(x)); using namespace std;
inline int read() { int data=0, w=1; char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') w=-1, ch=getchar(); while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar(); return data*w; }
const int maxn(210); int n; long double ans, f[maxn][2], g[maxn], m;
int main() { n=read(); m=read(); g[1]=f[0][1]=1.0000; for(RG int i=2;i<=n;i++) g[i]=g[i-1]/m; for(RG int i=0;i<n;i++) for(RG int j=i+1;j<=n;j++) { f[j][0]+=(j-i)*g[j-i]*(f[i][0]*(m-2.0000)/m+f[i][1]*(m-1.0000)/m); f[j][1]+=(j-i)*g[j-i]*f[i][0]/m; } ans=g[n]*n; for(RG int i=1;i<n;i++) ans+=1.0000*i*i*f[n-i][0]*g[i]; printf("%.10Lf\n", ans); return 0; }
|