uva 11637,

來源:互聯網
上載者:User

uva 11637,

題目連結:uva 11637 - Garbage Remembering Exam

題目大意:大白數裡有很詳細的題意。

解題思路:對於有序的序列來說,考慮每個位置為有效性的機率。C(2∗kn−1−x)∗A(2k2k)∗A(n−1−xn−1−x)A(n−1n−1)
x為考慮當前位置,然後與該位置距離小於等於k的位置個數。該位置有效話,則對應的要將原先鄰近的2*k個單詞放到另外的位置上。

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn = 1e5;int N, K;long double frc[maxn+5];double solve () {    if (N == 1)        return 0;    if (N - 2 * K - 1 <= 0)        return N;    double ret = 0;    for (int i = 1; i <= N; i++) {        int x = min(K, i - 1)  + min(K, N - i);        if (N >= x + 2 * K + 1)            ret += exp(frc[N-1-2*K] + frc[N-1-x] - frc[N-1] - frc[N - 1 - x - 2 * K]);    }    return N - ret;}int main () {    int cas = 1;    frc[0] = 0;    for (int i = 1; i <= maxn; i++)        frc[i] = frc[i-1] + log((long double)i);    while (scanf("%d%d", &N, &K) == 2 && N + K) {        printf("Case %d: %.4lf\n", cas++, solve());    }    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.