Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum,

來源:互聯網
上載者:User

Codeforces Round #259 (Div. 1)——Little Pony and Expected Maximum,

題目串連

  • 題意:
    輸入n、m,表示一個n面的色子(面上的值為1-n),投擲m次,求得到的最大值的期望(1 ≤ m, n ≤ 105).
  • 分析:
    假設當前得到的最大值是Max,那麼對應的機率是:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ),(1 <= k <= n);化簡就可以得到:sigma(C(m,k) * ((1 / n) ^ k )*(((Max - 1) / n) ^ (m - k)) ) - ((Max - 1) / n) ^ m,(0 <= k <= n);前半部分由二項式可以得到Max ^ m,那麼化簡結果就是Max ^ m - (Max - 1) ^ m。最後再乘以Max就是期望了。Max可以採用枚舉的方式
    感歎一下,才發現pow函數和快速冪的效率是一樣的。。
int main (){    int n, m;    while (~RII(n, m))    {        double ans = 0;        FE(Max, 1, n)        {            ans += Max * (pow((double)Max / n, m) - pow((Max - 1.0) / n, m));        }        printf("%.10f\n", ans);    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.