algorithm

13251

fungod 2022. 1. 25. 15:09

조약돌

조합 X  조합을 이용하면 너무 큰 숫자가 발생한다

따라서 확률로 계산해야 된다.

 

+) 뽑을 개수 K 보다 (같은 색깔의) 조약돌의 개수가 적으면  확률을 계산하지 않아도 된다

 

 

#include <iostream>
using namespace std;
using ll=long long;
double ans;
int main() {
	int N,K;
	ll total=0;
	cin>>N;	
	int arr[N];
	for(int i=0;i<N;i++){
		cin>>arr[i];
		total+=arr[i];
	}
	cin>>K;
	for(int i=0;i<N;i++){
		double temp=1;
		double tot=total;
        if(arr[i]<K) continue;
	for(int j=K;j>=1;j--){
		temp*=(arr[i]/(double)tot);
		arr[i]--;tot--;
	}
	ans+=temp;
	}
	cout<<fixed;
	cout.precision(13);
	cout<<ans;
	return 0;
}