26. 旦e徨鹿 - simplified
? 枠深]曳^竜聴羆
? 朕烹挫凝e ? = 0, 1, ? , ? ? 1 議徨鹿栽
? 恬隈詐擁 0 ~ 2 ?
? 1
C 0...000
C 0...001
C 0...010
C 0...011
C ...
C 1...111
27. 旦e徨鹿 - original
? 朕烹挫凝e ? 議徨鹿栽
? 嗤匯乂喘音欺議 bit 奕Nk芯脳猷子深]麿
for ( int sub = sup ; ; sub = ( sub - 1 ) & sup ) {
// do something
if ( sub == 0 ) break ;
}
29. 旦e徨鹿 2 - simplified
? 枠深] ? = 0, 1, ? , ? ? 1
? 箭徨
int lower = ( 1 << k ) - 1, upper = 1 << n ;
for ( int comb = lower ; comb < upper ; ) {
// do something
comb = next_permu( comb ) ;
}
30. 旦e徨鹿 2 - simplified
? 嶷c頁孀竃和匯電双徭失D心心
int next_permu( int p ) {
int x = lowbit( p ), y = p + x ;
return y | ( ( p & ~y ) / x >> 1 ) ;
// or return y | ( ( p & ~y ) >> ( lg( x ) + 1 ) ) ;
}