noip 2001提高组 第3道 统计单词个数 想知道哪里错了。。

type
node=record
l,s:longint;
end;
var
n,i,w,j,p,k,sl,a,t,h,min:longint;
s,s1:string;
dic:array[1..6]of string;
st:array[1..200,1..200]of string;
f:array[1..200,0..40]of longint;
g:array[1..200,1..200]of longint;
len:array[1..200]of node;
begin
assign(input,'03.in');reset(input);
assign(output,'03.out');rewrite(output);
readln(p,k);
fillchar(dic,sizeof(dic),0);
fillchar(f,sizeof(f),0);
fillchar(len,sizeof(len),0);
a:=1;
for i:=1 to p do
begin
readln(s1);
s:=s+s1;
end;
readln(sl);
for i:=1 to sl do
readln(dic[i]);
for i:=1 to length(s) do
begin
min:=maxint;
for j:=1 to sl do
begin
if copy(s,i,length(dic[j]))=dic[j] then
begin
len[i].s:=1;
if length(dic[j])<min then
min:=length(dic[j]);
end;
end;
len[i].l:=min;
end;
for i:=1 to length(s) do
for j:=i to length(s) do
begin
for h:=i to j do
if ((h+len[h].l-1)<=j) and (len[j].s<>0) then
inc(g[i,j]);
end;
for j:=1 to k do
for i:=j to length(s) do
begin
for h:=j to i-1 do
begin
t:=g[h+1,i];
if f[i,j]<f[h,j-1]+t then
f[i,j]:=f[h,j-1]+t;
end;
end;
writeln(f[length(s),k]);
close(input);close(output);
end.

楼主的程序几分啊?
这道题大致可以用两种方法:
1 动态规划 较常用 楼主百度一下吧
http://blog.sina.com.cn/s/blog_51cea4040100g88w.html
http://www.sdgh.net/bmzc/person/hwl/ao_sai/jsfd/dtgh5.htm
http://smqqlzy.blog.163.com/blog/static/128227861200962010121550/
2 kmp+floyd 可能比较麻烦,等楼主厉害了可以找一下这方面的资料
PS:第二种方法不知道网上有没有,貌似是我发现的,绝对正确。
温馨提示:答案为网友推荐,仅供参考
相似回答