one dimension dp, scan from the last row