Add space optimized DP version.