Card Collector
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.
As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.
InputThe first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards you need the collect. The second line contains N numbers p1, p2, ..., pN, (p1 + p2 + ... + pN <= 1), indicating the possibility of each card to appear in a bag of snacks.
Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag. OutputOutput one number for each test case, indicating the expected number of bags to buy to collect all the N different cards.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4. Sample Input
1
0.1
2
0.1 0.4
Sample Output
10.000
10.500
题意:方便面里都可以吃出卡片,吃出每种卡片的概率已给出,问你集齐一套卡片的期望
思路:这个只要会算期望了,基本解决,弱的我连期望也不会了,概率学的圈还回去了
给出一组样例解释,一点即懂,类似于gcd那个题目,Goal=每张卡片的期望-两张卡片的期望+三张……
每张卡片的期望就等于1/p[i],
以样例二为例,集齐单张卡片的期望 temp[1|1]=1/0.1=10 temp[1|2]=1/0.4=2.5
集齐两张temp[2|1,2]=1/(0.1+0.4)=2
ans=temp[1]-temp[2]=12.5-2=10.5
3 0.1 0.2 0.3
temp[1|1]=10 temp[1|2]=5 temp[1|3]=3.333
temp[2|1,2]=3.333 temp[2|1,3]=2.5 temp[2|2,3]=2
tenp[3|1,2,3]=1.6666
10+5-3.333+3.333-2.5-2+1.66=12.166
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define MOD 1000000007
#define N 110
double p[N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
double sum=0;
for(int i=0;i