标签:
1->2 , 2->3 , 3->1; 一次
#include <cstdio> using namespace std; double a[5001][5001]; //当时不知道能开辣么大 ~~~~(>_<)~~~~ int main() { int n, k; double ans; for(int i=1; i<=5000; i++) a[i][1]=1.0/i; for(int i=2; i<=5000; i++){ for(int j=2; j<=i; j++){ if(i==j) a[i][j] = a[i-1][j-1]*1.0/i; else a[i][j] = 1.0/i*a[i-1][j-1]+(i-1)*1.0/i*a[i-1][j]; } } while( scanf("%d%d", &n, &k)!=-1 ){ ans = 0.0; for(int i=1; i<=k; i++) ans += a[n][i]; printf("%.4f\n", ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/ash_zheng/article/details/44754095