1 条题解
-
0
C++ :
#include <bits/stdc++.h> #define xx first #define yy second #define mp make_pair #define pb push_back #define fill( x, y ) memset( x, y, sizeof x ) #define copy( x, y ) memcpy( x, y, sizeof x ) using namespace std; typedef long long LL; typedef pair < int, int > pa; const int MAXN = 15; const int MAXM = 55; const int MAXV = 1025; int G[MAXN], bit[MAXV], cnt[MAXV], n, m; long double f[MAXV][MAXM], g[MAXV][MAXM], C[MAXM][MAXM], ans; inline int lowbit(int x) { return x & -x; } int main() { #ifdef wxh010910 freopen( "data.in", "r", stdin ); #endif scanf( "%d%d", &n, &m ); for( int i = 1 ; i <= m ; i++ ) { int x, y; scanf( "%d%d", &x, &y ); x--; y--; G[ x ] |= 1 << y; G[ y ] |= 1 << x; } for( int i = 0 ; i <= m ; i++ ) { C[ i ][ 0 ] = 1; for( int j = 1 ; j <= i ; j++ ) C[ i ][ j ] = C[ i - 1 ][ j ] + C[ i - 1 ][ j - 1 ]; } for( int S = 1, u ; S < ( 1 << n ) ; S++ ) { bit[ S ] = __builtin_popcount( S ); if( bit[ S ] == 1 ) { g[ S ][ 0 ] = 1; continue; } for( int i = 0 ; i < n ; i++ ) if( ( S >> i ) & 1 ) cnt[ S ] += bit[ S & G[ i ] ]; cnt[ S ] >>= 1; u = lowbit( S ); for( int T = S - 1 & S ; T ; T = T - 1 & S ) if( T & u ) for( int i = 0 ; i <= cnt[ T ] ; i++ ) for( int j = 0 ; j <= cnt[ S ^ T ] ; j++ ) f[ S ][ i + j ] += g[ T ][ i ] * C[ cnt[ S ^ T ] ][ j ]; for( int i = 0 ; i <= cnt[ S ] ; i++ ) g[ S ][ i ] = C[ cnt[ S ] ][ i ] - f[ S ][ i ]; } for( int i = 0 ; i <= m ; i++ ) ans += f[ ( 1 << n ) - 1 ][ i ] / C[ m ][ i ]; ans /= m + 1; printf( "%.6Lf\n", ans ); }
- 1
信息
- ID
- 961
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者