bfs and dp