Search, greedy and DP
Binary search on the answer, greedy rules after sorting with an exchange argument, and the DP patterns that appear in contests.
About 7 hours of study
Learning objectives
- Binary search a feasibility check
- Justify a greedy rule
- Write counting, LIS and knapsack DPs
Lessons
- 1
Binary search on the answer
When checking a guess is easy and the answer is a number, search for the best answer with binary search.
- 2
Sorting first, then greedy
Sort pairs, choose a comparator, and let the order make a greedy choice correct, with an exchange argument to check it.
- 3
Dynamic programming in contests
Counting ways modulo 10⁹+7, the longest increasing subsequence, and the 1D knapsack: the DP patterns that keep coming back.
Module practice
- CP: Integer square rootEasy
- CP: Cutting ropesMedium
- CP: Split the jobsHard
- CP: Most items for the budgetEasy
- CP: The most meetingsMedium
- CP: The fewest roomsHard
- CP: Climbing stairs, modulo a primeEasy
- CP: Longest increasing subsequenceMedium
- CP: The most valuable bagHard