search & sort & dynamic programming