w****x 发帖数: 2483 | 1 Print neatly
一下忘了怎么做了,花了半小时,处理下标很痛苦啊。
忽然发现没想的那么复杂。
//you have a list of words, you want to print them
//on a paper with width n. when printing, each
//word must be separated by one blank except the blanks after the last word.
Find the fewest
//possible blanks except the last line.
//f(i, j) = [1 + f(i+1, j+len(i)+1) ] || [nLen - j-len(i) + f(i+1,0)]
int GetLeastBlanks(int a[], int n, int nLen)
{
if (NULL == a || n <= 0 || nLen <= 0)
return -1;
int rec[100][100] = { 0 };
for (... 阅读全帖 |
|