Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessCheng committed Jul 4, 2020
1 parent 46b9a72 commit 2692ccc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion copypasta/bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func bitsCollection() {
// ^n+1 = (-1-n)+1 = -n
lowbit := func(n int64) int64 { return n & -n }

isPow2 := func(x int64) bool { return x > 0 || x&(x-1) == 0 }

bits31 := func(n int) []byte {
bits := make([]byte, 31)
for i := range bits {
Expand All @@ -110,7 +112,7 @@ func bitsCollection() {
return
}

_ = []interface{}{lowbit, bits31, _bits31, _bits32, digitSum}
_ = []interface{}{lowbit, isPow2, bits31, _bits31, _bits32, digitSum}
}

// https://halfrost.com/go_s2_de_bruijn/
Expand Down
4 changes: 4 additions & 0 deletions copypasta/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ func dpCollections() {
todo LC691 https://leetcode-cn.com/problems/stickers-to-spell-word/
LC1125 https://leetcode-cn.com/problems/smallest-sufficient-team/
LC943 https://leetcode-cn.com/problems/find-the-shortest-superstring/
枚举子集,复杂度 O(3^n)
dp[s] = min(valid dp[s^sub]) + 1
todo LC1494/双周赛29D https://leetcode-cn.com/problems/parallel-courses-ii/
todo 汉密尔顿路径/回路 Hamiltonian path
*/

Expand Down
27 changes: 26 additions & 1 deletion copypasta/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,34 @@ func loopCollection() {
loopSubset := func(n, subset int) {
sub := subset
for ok := true; ok; ok = sub != subset {
// do(sub)
// do(sub)...

sub = (sub - 1) & subset
}

{
// 非空子集
for sub := subset; sub > 0; sub = (sub - 1) & subset {
// do(sub)...

}
}

{
// 真子集
for sub := (subset - 1) & subset; sub != subset; sub = (sub - 1) & subset {
// do(sub)...

}
}

{
// 非空真子集
for sub := (subset - 1) & subset; sub > 0; sub = (sub - 1) & subset {
// do(sub)...

}
}
}

// 枚举大小为 n 的集合的大小为 k 的子集(按字典序)
Expand Down

0 comments on commit 2692ccc

Please sign in to comment.