wrong approach, going to solve it as a dp
completed as dp