1d dynamic programming for word break problem