dynamic programming
 
Magnets