比赛 防止颓废的小练习v0.15 评测结果 EEEEEEEEEE
题目名称 统计单词数 最终得分 0
用户昵称 ConanQZ 运行时间 0.006 s
代码语言 Pascal 内存使用 0.51 MiB
提交时间 2016-10-17 21:11:32
显示代码纯文本
program P1024;
uses math;
var
i,n,m:longint;
s:string;
word:array[1..10]of string;
dp:array[0..210,0..50]of longint;
w:array[1..210,1..210]of longint;

function check(st:longint; s1:string):boolean;
var
i:longint;
begin
 for i:=1 to length(s1) do
    if s[st+i-1]<>s1[i] then
      exit(false);
 exit(true);
end;

function search(l,r:longint):longint;
var
i,j:longint;
ans:longint;
begin
ans:=0;
 for i:=l to r do
    for j:=1 to m do
       if (i+length(word[j])-1<=r)and(check(i,word[j])) then
         begin
          inc(ans);
          break;
         end;
exit(ans);
end;

procedure work;
var
n,k,j,i,l:longint;
s1:string;
begin
readln(n,k);
for i:=1 to n do
  begin
   readln(s1);
   s:=s+s1;
  end;
readln(m);
for i:=1 to m do readln(word[i]);
for i:=1 to length(s) do
   for j:=1 to length(s) do
     w[i,j]:=search(i,j);
for i:=1 to length(s) do
  dp[i,1]:=w[1,i];
for i:=1 to length(s) do
  for j:=2 to min(i,k) do
    for l:=j-1 to i-1 do
        dp[i,j]:=max(dp[i,j],dp[l,j-1]+w[l+1,i]);
writeln(dp[length(s),k]);
end;

begin
assign(input,'stat.in');reset(input);
assign(output,'stat.out');rewrite(output);
readln(n);
for i:=1 to n do
  work;
end.