dp with size n+1, where n is the number of words, and set all values to infinity except dp[0] which is set to 0.dp array with the minimum cost found for arranging words up to the current word.dp array, iterate backwards from the second last word to find the minimum cost excluding the last row.