HDU 4159 Indomie ( 组合数学 )

 

HDU 4159 Indomie ( 组合数学 )

 

HDU 4159 Indomie ( 组合数学 )_第1张图片

 

#include <cstdio>
typedef __int64 LL;
#define MAXN 101
int n, s;
LL po[ MAXN ];

void init()
{
    po[0] = 1;
    for( int i = 1; i < MAXN; ++i )
        po[i] = po[i-1] * 2;
}

double CC( int n, int m )
{
    double res = 1;
    for( int i = 0; i < m; ++i )
        res *= (double)(n-i) / (i+1);
    return res;
}

int main()
{
    init();
    while( ~scanf( "%d %d", &n, &s ) )
    {
        if( s == 0 )        puts( "0.00000");
        else if( s > n )    puts( "100.00000");
        else
        {
            double res1 = 0, res2 = 0;
            for( int i = 0 ; i <= s; ++i )
            {
                res1 += CC( n, i )* po[n-i];
                if( i == s - 1 )
                    res2 = res1;
            }
            printf( "%.5lf\n", 100.0 * res2 / res1 );
        }
        
    }
}
代码君

 

你可能感兴趣的:(dom)