From http://blog.csdn.net/shuangde800
Question: Click to open the link
Question
Give a string and divide it into k blocks. For example, the string "helloworld" is divided into two blocks, "hello", "world"
The letters in each block can be sorted in any order.
The final string contains the same consecutive letters as a chunk. What is the minimum total number of chunks?
Ideas
F [I] [J]: The minimum chunks in the last position of the J-TH Block
For each separate piece, its chunks is equal to the number of different letters that appear
Chunks of block I as chunks [I]
If the last digit of the I-1 block is the same as the first digit of the I block, you can merge the two, and the total chunks can reduce one
F [I] [J] = min {if the K-bit of the I-1 block is different from the first of the I-block: F [I-1] [k] + chunks [I],
If the K-bit of the I-1 block is the same as the first of the I-block: F [I-1] [k] + chunks [I]-1}
Code