从$O(3^n)$优化到$O(n2^n)$
int mx = (1<<n)-1; //3^n REP(i,0,mx) if (dp[i]) { int j = ~i&mx; for (int k=j; k; k=(k-1)&j) dp[i|k] = 1; } //n2^n REP(i,0,mx) if (dp[i]) { REP(j,0,n-1) dp[i|1<<j]=1; }
从$O(3^n)$优化到$O(n2^n)$
int mx = (1<<n)-1; //3^n REP(i,0,mx) if (dp[i]) { int j = ~i&mx; for (int k=j; k; k=(k-1)&j) dp[i|k] = 1; } //n2^n REP(i,0,mx) if (dp[i]) { REP(j,0,n-1) dp[i|1<<j]=1; }