DOKICODE
書斎

動的計画法

動的計画法は、同じ形の小さな問題の答えを組み合わせて全体の答えを作り、その答えを保存して同じ計算を繰り返さない手法です。難しいのは状態が何を表すかを決めることで、コード自体は短いことがよくあります。

20 章 465 問の、いちばん大きな問題集です。入門 DP とグリッド DP から始まり、ナップサック、LCS と LIS、分割 DP、状態機械 DP を経て、区間 DP、bit DP、桁 DP、木 DP、グラフ上の DP、ゲーム DP、確率 DP へと進みます。具体的な解の復元やジャンプゲームの変形といった特集もあります。再帰に慣れていて、DP を順序立てて最後まで練習したい人に向いています。

465 問レーティング 1262–312520 章
書斎を開く

誰かと一緒にこの問題集を進めたいなら、ログインして書斎を開いてみてください。ヒロインが一問ずつ出題してくれます。

一、入門 DP

二、Grid DP

三、Knapsack

§3.5 Tree Knapsack(任意)任意

問題レーティング
3562. Maximum Profit From Trading Stocks with Discounts2458

四、典型的なLinear DP

五、Partition DP

§5.1 分割できるかの判定

問題レーティング
2369. Check If There Is a Valid Partition for the Array1780
139. Word Break未評価

六、State Machine DP

七、その他のLinear DP

§7.6 多次元 DP

問題レーティング
2222. Number of Ways to Select Buildings1657
2826. Sorting Three Groups1721
2400. Number of Ways to Reach a Position After Exactly K Steps1751
1262. Greatest Sum Divisible by Three1762
3332. Maximum Points Tourist Can Earn1828
3176. Find the Maximum Length of a Good Subsequence I1849
1269. Number of Ways to Stay in the Same Place After Some Steps1854
3250. Find the Count of Monotonic Pairs I1898
3218. Minimum Cost for Cutting Cake I未評価
3122. Minimum Number of Operations to Satisfy Conditions1905
576. Out of Boundary Paths未評価
403. Frog Jump未評価
3725. Count Ways to Choose Coprime Integers From Rows1982
1223. Dice Roll Simulation2008
1320. Minimum Distance to Type a Word Using Two Fingers2028
3366. Minimum Array Sum2040
1575. Count All Possible Routes2055
3154. Find Number of Ways to Reach the K Th Stair2071
2318. Number of Distinct Roll Sequences2090
3469. Find Minimum Cost to Remove Array Elements2112
2746. Decremental String Concatenation2126
1444. Number of Ways of Cutting a Pizza2127
3320. Count the Number of Winning Sequences2153
3429. Paint House IV2166
2896. Apply Operations to Make Two Strings Equal2172
1420. Build Array Where You Can Find the Maximum Exactly K Comparisons2176
3193. Count the Number of Inversions2266
1079. Letter Tile Possibilities未評価
1866. Number of Ways to Rearrange Sticks with K Sticks Visible2333
2312. Selling Pieces of Wood2363
3177. Find the Maximum Length of a Good Subsequence II2365
1884. Egg Drop with 2 Eggs AND N Floors未評価
887. Super Egg Drop2377
920. Number of Music Playlists2400
3336. Find the Number of Subsequences with Equal Gcd2403
1388. Pizza with 3n Slices2410
903. Valid Permutations for Di Sequence2433
1900. The Earliest AND Latest Rounds Where Players Compete2455
1531. String Compression II2576
1883. Minimum Skips to Arrive at Meeting on Time2588
964. Least Operators to Express Number2594
3343. Count Number of Balanced Permutations2615
1787. Make the XOR of All Segments Equal to Zero2640
3509. Maximum Product of Subsequences with an Alternating Sum Equal to K2703
3441. Minimum Cost Good Caption2765
3539. Find Sum of Array Product of Magical Sequences2694
2060. Check If an Original String Exists Given Two Encoded Strings2804
2809. Minimum Time to Make Array Sum at Most X2979
3003. Maximize the Number of Partitions After Operations3039
3225. Maximum Score From Grid Operations3028

八、Interval DP

九、Bitmask DP

§9.1 順列型 Bitmask DP ① 隣接に依存しない

問題レーティング
526. Beautiful Arrangement未評価
1799. Maximize Score After N Operations未評価
3533. Concatenated Divisibility2257
3530. Maximum Profit From Valid Topological Order in Dag2353

§9.3 巡回セールスマン問題(TSP)

問題レーティング
943. Find the Shortest Superstring2186

十、Digit DP

§10.2 条件を満たす要素の値の総和を求める

問題レーティング
233. Number of Digit One未評価
3753. Total Waviness of Numbers in Range II2297

§10.3 その他のDigit DP

問題レーティング
3677. Count Binary Palindromic Numbers2223
3348. Smallest Divisible Digit Product II3101

十一、DP の高速化

§11.2 Monotonic Stackによる DP の高速化

問題レーティング
1335. Minimum Difficulty of a Job Schedule2035
2866. Beautiful Towers II2072
2617. Minimum Number of Visited Cells in a Grid2582

§11.5 Trieによる DP の高速化

問題レーティング
139. Word Break未評価
2707. Extra Characters in a String未評価
472. Concatenated Words2300

§11.7 Convex Hull Trick(傾き最適化)

問題レーティング
3494. Find the Minimum Amount of Time to Brew Potions未評価
3500. Minimum Cost to Divide Array Into Subarrays未評価
3693. Climbing Stairs II未評価

十二、Tree DP

§12.2 木の最大独立集合

問題レーティング
337. House Robber III未評価
2646. Minimize the Total Price of the Trips2238
3544. Subtree Inversion Sum2545

§12.3 木の最小支配集合

問題レーティング
968. Binary Tree Cameras2124

十三、グラフ上の DP

十三、グラフ上の DP

問題レーティング
3543. Maximum Weighted K Edge Path2110
913. Cat AND Mouse2800
1728. Cat AND Mouse II2849

十四、Game Theory DP

十五、確率・期待値DP

特集:具体的な解の復元(解の出力)

特集:前後からの分解

特集:前後からの分解

問題レーティング
724. Find Pivot Index未評価
1991. Find the Middle Index in Array未評価
3707. Equal Score Substrings1262
2270. Number of Ways to Split Array1334
2256. Minimum Average Difference1395
1422. Maximum Score After Splitting a String未評価
238. Product of Array Except Self未評価
1493. Longest Subarray of 1s After Deleting One Element1423
845. Longest Mountain in Array1437
2012. Sum of Beauty in the Array1468
2909. Minimum Sum of Mountain Triplets II1479
2483. Minimum Penalty for a Shop1495
1525. Number of Good Ways to Split a String1500
3583. Count Special Triplets1510
3354. Make Array Elements Equal to Zero未評価
1930. Unique Length 3 Palindromic Subsequences1533
2874. Maximum Value of an Ordered Triplet II1583
1664. Ways to Make a Fair Array1590
123. Best Time to Buy AND Sell Stock III未評価
3698. Split Array with Minimum Difference1649
3598. Longest Common Prefix Between Adjacent Strings After Removals1655
2222. Number of Ways to Select Buildings1657
1031. Maximum Sum of Two Non Overlapping Subarrays1680
689. Maximum Sum of 3 Non Overlapping Subarrays未評価
2420. Find All Good Indices1695
2100. Find Good Days to Rob the Bank1702
926. Flip String to Monotone Increasing未評価
334. Increasing Triplet Subsequence未評価
1653. Minimum Deletions to Make String Balanced1794
1186. Maximum Subarray Sum with One Deletion1799
3738. Longest Non Decreasing Subarray After Replacing at Most One Element1811
42. Trapping Rain Water未評価
2711. Difference of Number of Distinct Values on Diagonals未評価
1477. Find Two Non Overlapping Sub Arrays Each with Target Sum1851
1671. Minimum Number of Removals to Make Mountain Array1913
2906. Construct Product Matrix2075
3334. Find the Maximum Factor Score of Array未評価
2167. Minimum Time to Remove All Cars Containing Illegal Goods2219
2484. Count Palindromic Subsequences2223
2163. Minimum Difference in Sums After Removal of Elements2225
2565. Subsequence with the Minimum Score2432
1995. Count Special Quadruplets未評価
2552. Count Increasing Quadruplets2433
3302. Find the Lexicographically Smallest Valid Sequence2474
3404. Count Special Subsequences2445
3303. Find the Occurrence of First Almost Equal Substring2509
3410. Maximize Subarray Sum After Removing All Occurrences of One Element2844
3003. Maximize the Number of Partitions After Operations3039

特集:X を Y に変える

特集:ジャンプゲーム

その他

トラック 2 の 3 番目です。個数制限付きナップサックと木上のナップサックの 2 セクションは任意として発展編に回されるので、ルートは主要な章をそのまま進みます。

レーティングは zerotrac さんによる LeetCode コンテストレーティングです。zerotrac のレーティングがない問題は「未評価」と表示されます。

書斎を開く