HEU 4048 Picking Balls

 1 /**************************************
 2Problem: HEU 4048 Picking Balls
 3Time: 0.0000 s
 4Memory: 284 k 
 5Accepted Time: 2009-03-28 12:01:19
 6Tips: 求概率 
 7**************************************/

 8 #include  < stdio.h >
 9 long   long  fun( int  n, int  m)
10 {
11    int i,j;
12    long long sum;
13    if (m>n/2)m=n-m;
14    sum=1;
15    for(i=n-m+1,j=1;i<=n,j<=m;i++,j++)
16        sum=sum*i/j;
17    return sum;
18}

19 int  main()
20 {
21    int n,k;
22    while(1)
23    {
24        scanf("%d%d",&n,&k);
25        if(n==-1&&k==-1)break;
26        int i,a[100],b[100],sum=0;
27        for(i=0;i<n;i++)
28        {
29            scanf("%d",&a[i]);
30            sum+=a[i];
31        }

32        for(i=0;i<n;i++)scanf("%d",&b[i]);
33        if(n==0)
34        {
35            if(k==0)printf("1.00000\n");
36            else printf("0.00000\n");
37            continue;
38        }

39        double sum1=(double)1.0/fun(sum,k);
40        for(i=0;i<n;i++)
41        {
42            if(a[i]<b[i])break;    
43            sum1*=fun(a[i],b[i]);
44        }

45        if(i==n)printf("%.5lf\n",sum1);
46        else printf("0.00000\n");
47    }

48    return 0;
49}

50

你可能感兴趣的:(404)