标签:
集合幂级数其实就是一种集合到数的映射,并且我们针对集合的一些操作(or and xor and specil or )为这种映射定义运算.其中一些东西可以通过某些手段将其复杂度降低.
还要写一些其他两种.
1 /************************************************************** 2 Problem: 4036 3 User: idy002 4 Language: C++ 5 Result: Accepted 6 Time:3584 ms 7 Memory:13092 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cmath> 12 #define eps 1e-10 13 #define N 20 14 15 int n, bound; 16 long double f[1<<N]; 17 18 int sg( long double x ) { return (x>-eps)-(x<eps); } 19 20 void trans() { 21 for( int i=0; i<n; i++ ) { 22 int ss=bound^(1<<i); 23 f[ss|(1<<i)] += f[ss]; 24 for( int s=(ss-1)&ss; s!=ss; s=(s-1)&ss ) 25 f[s|(1<<i)] += f[s]; 26 } 27 } 28 void inverse() { 29 for( int i=0; i<n; i++ ) { 30 int ss=bound^(1<<i); 31 f[ss|(1<<i)] -= f[ss]; 32 for( int s=(ss-1)&ss; s!=ss; s=(s-1)&ss ) 33 f[s|(1<<i)] -= f[s]; 34 } 35 } 36 37 int main() { 38 scanf( "%d", &n ); 39 bound = (1<<n)-1; 40 for( int s=0; s<=bound; s++ ) 41 scanf( "%Lf", f+s ); 42 trans(); 43 for( int s=0; s<=bound; s++ ) { 44 if( sg(f[s]-1)==0 ) 45 f[s] = 0; 46 else 47 f[s] = 1/(f[s]-1); 48 } 49 inverse(); 50 if( sg(f[bound])==0 ) 51 printf( "INF\n" ); 52 else 53 printf( "%.10Lf\n", f[bound] ); 54 }
标签:
原文地址:http://www.cnblogs.com/idy002/p/4564870.html