Fleecing the Raffle Gym - 101550F(概率)

在這裏插入圖片描述

題意:
所有數選p個,但你可以加入a個自己的數。求選到的數中你加入數的個數恰好爲1個的概率

思路:
在這裏插入圖片描述

#include <cstdio>
#include <cstring>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

const int maxn = 1e7 + 7;
double C(int n,int p,int a) {
    double ans = 1.0;
    for(int i = 1;i <= p;i++) {
        ans *= (n - i + 1);
        ans /= (n + a - i + 1);
    }
    return ans * a * p / (n - p + 1);
}

int main() {
    int n,p;scanf("%d%d",&n,&p);
    int a = n / (p - 1);
    double ans = C(n,p,a);
    printf("%.10f\n",ans);
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章