↓快轉到主要內容

Combinatorics

Math 數學技巧
·5 分鐘
演算法 Math Combinatorics Geometry Brainteaser
組合計數(配對數、切分方式)、第 k 個排列逐位決定、幾何(最近點、餘弦定理、三角不等式)、排序或觀察之後變成公式的題目,以及直式進位、進位制轉換和快速冪
LeetCode 2963: Count the Number of Good Partitions
·1 分鐘
LeetCode Hard Math Combinatorics Hash-Table Array
LeetCode 2963 解題筆記:同一個數的所有出現位置必須在同一段,用最後出現位置把陣列切成 b 個不可再分的區塊;區塊之間可切可不切,答案是 2^(b-1)
LeetCode 2912: Number of Ways to Reach Destination in the Grid
·2 分鐘
LeetCode Hard Dynamic-Programming State-Machine Math Combinatorics
LeetCode 2912 解題筆記:格子太多,但相對終點只分四類:終點、同一列、同一行、都不同;每一類的總方法數一起轉移,O(k)
LeetCode 60: Permutation Sequence
·1 分鐘
LeetCode Hard Math Combinatorics Recursion
LeetCode 60 解題筆記:k 改成 0-indexed,第一位決定之後剩下 (n-1)! 種排法;k // (n-1)! 就是第一位在剩下的數字裡排第幾,取出後繼續處理下一位
LeetCode 22: Generate Parentheses
·1 分鐘
LeetCode Daily Medium String Backtracking Recursion Combinatorics Parentheses
使用回溯法生成所有有效的括號組合
LeetCode 3518: Smallest Palindromic Rearrangement II
·2 分鐘
LeetCode Hard Math Combinatorics Counting Hash-Table String
LeetCode 3518 解題筆記:回文由左半邊決定,變成「多重集合的第 k 個排列」;逐位試每個字元,用排列數判斷第 k 個落在哪個分支,排列數可以 O(1) 更新