首页 > 代码库 > HDU 4159 Indomie ( 组合数学 )

HDU 4159 Indomie ( 组合数学 )

 

HDU 4159 Indomie ( 组合数学 )

 

 

#include <cstdio>typedef __int64 LL;#define MAXN 101int 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 );        }            }}
代码君

 

HDU 4159 Indomie ( 组合数学 )