dynamic programming one. Doesn't work yet