speed-up 30
speed-up 31 and add version using dp