minimalistic approach to the dp assignment, less memory issues