SGU--495(概率,数学)

2015-01-02 18:00:34

思路:....怎么说呢 SGU难得的水题,直接递推吧。

  dp[i]表示第i个人期望得到的prize,那么答案就是Sigma(dp[k]) (1 <= k <= M),dp[i] = (N - dp[i - 1]) / N,然后就不用数组啦。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cmath>
 5 #include <vector>
 6 #include <map>
 7 #include <set>
 8 #include <stack>
 9 #include <queue>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define lp (p << 1)
14 #define rp (p << 1|1)
15 #define getmid(l,r) (l + (r - l) / 2)
16 #define MP(a,b) make_pair(a,b)
17 typedef long long ll;
18 typedef unsigned long long ull;
19 typedef pair<int,int> pii;
20 const int INF = (1 << 30) - 1;
21 const int maxn = 100010;
22 
23 double dp;
24 int N,M;
25 
26 int main(){
27     while(scanf("%d%d",&N,&M) != EOF){
28         double ans;
29         ans = dp = 1.0;
30         for(int i = 2; i <= M; ++i){
31             dp = (N - ans) / (double)N;
32             ans += dp;
33         }
34         printf("%.10f\n",ans);
35     }
36     return 0;
37 }

 

posted @ 2015-01-02 18:02  Naturain  阅读(155)  评论(0编辑  收藏  举报