Code:

#include <bitset>
#include <math.h>
int main()
{
static const unsigned n = 27;
static unsigned int w[ n ] = {10,12,10,4,12,29,7,27,4,
7,29,29,12,12,7,29,7,4,4,3,13,27,12,14,7,4,10};
static float p[ n ] = {8.34,10.59,7.6,0.8,10.32,82.18,5.47,45.27,1.34,5.31,
63.92,61.09,11.18,10.03,4.39,59.21,3.37,0.48,2.27,
0.41,16.39,38.09,10.67,21.45,5.4,2.02,9.22};
static const unsigned nc = 1 << n;
double pr = 0.0f;
unsigned int sumv = 0;
unsigned int sumw = 0;
float sump = 0.0f;
double RES = 0.0f;
unsigned int i;
for ( i = nc; i--; )
{
std::bitset < n > v = i;
sumv = v.count();
if ( sumv < 18 ) continue;
sumw = 0;
sump = 0;
pr = pow( 0.6 , sumv ) * pow( 0.4 , n - sumv );
unsigned int j;
for ( j = n; j--; ) {
if ( v[ n - j - 1 ] ) {
sumw += w[ j ];
sump += p[ j ];
}
}
if ( sumw >= 255 && sump >= 308.01 ) RES += pr;
}
printf( "%2.6f\n" , RES);
return 0;
}