这题做了2个多小时,(f[k,j-1]+n m[k+1,i]); 条件限制:if kj-1 n m[i,j]表示i到j单词的多少,关键是推n m数组. 在这里,若找到一个最短的单词则将相应的n m数组加1,是一个很巧的办法. var n,m,p,i,j,k,x,y,l:longint; s, a:array[1..6] of string; f:array[0..200,0..40] of longint; n m:array[1..200,1..200] of longint; f nction max(a,b:longint):longint; begin if ab then exit(a); exit(b); end;proced re n mn m;varmin,i,j,p,q,l:longint;beginfor i:=1 to length(s) dobeginmin:=maxint;for j:=1 to m do begin l:=pos(a[j],copy(s,i,length(s)-i+1)); if (l=1)and(length(a[j])min) then min:=length(a[j]); end;if minmaxint thenfor p:=1 to i do for q:=i+min-1 to length(s) do inc(n m[p,q]);end;end; begin readln(n,p); for i:=1 to n do begin readln(st); s:=s+st; end; l:=length(s); readln(m); for i:=1 to m do readln(a[i]); n mn m; for i:=1 to l do for j:=0 to p do for k:=0 to i-1 do if k=j-1 then f[i,j]:=max(f[i,j],f[k,j-1]+n m[k+1,i]); writeln(f[l,p]); end.