CP Pattern Recognition
CP Pattern Recognition
Recognizing patterns in problems is one of the biggest skills in CP. Here's how you can develop it step by step.
■ Sorting + Greedy
- If the problem involves minimizing/maximizing a value, sorting first often helps.
- Example: Given a list of events and a budget, maximize the number of events attended.
- Sorting by cost and using a greedy approach is often correct.
■ Graph Problems
- If a problem mentions "shortest path" → Dijkstra / BFS.
- If a problem mentions "connected components" → DFS / Union-Find.
- If a problem is about finding a cycle → DFS with cycle detection.