0Pricing
Competitive Programming Academy · Lesson

Trim the Search Space Smartly

Fix one variable and search the rest.

Smaller Search, Same Answer

Sometimes brute force is just barely too slow. The fix is to shrink what you search without losing any correct answer. 🙂

Fix One Variable

A powerful trick is to fix one variable by looping over it, then solve the rest faster. You trade a full search for many small ones.

All lessons in this course

  1. Brute Force Is a Valid Strategy
  2. Enumerate with itertools
  3. Bitmask Subset Enumeration
  4. Trim the Search Space Smartly
← Back to Competitive Programming Academy