Iterative DP/Brute force