ac1050.pas

来自「某牛人写的acm.tongji.edu.cn上大部分ac的代码,仅供学习研究,请」· PAS 代码 · 共 31 行

PAS
31
字号
program tju1050;
const
  maxn=100;
var
  w:array[1..maxn]of string;
  l:array[1..maxn]of byte;
  ans:array[0..255]of byte;
  s:string;
  t,u,n,i,j:word;
begin
  readln(t);
  for u:=1 to t do begin
    readln(s);
    readln(n);
    for i:=1 to n do begin
      readln(w[i]);
      l[i]:=length(w[i]);
    end;

    fillchar(ans,sizeof(ans),255);
    ans[0]:=0;
    for i:=1 to length(s) do
      for j:=1 to n do
        if l[j]<=i then
          if copy(s,i-l[j]+1,l[j])=w[j] then
            if ans[i-l[j]]+1<ans[i] then ans[i]:=ans[i-l[j]]+1;

    writeln(ans[length(s)]);
  end;
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?