ac1271.pas
来自「这是在网络上搜集到的在东京大学的ACM上面解决的一些题目的源码」· PAS 代码 · 共 30 行
PAS
30 行
program tju1271;
const
maxl=255;
var
s:array[0..maxl]of char;
f:array[1..maxl,1..maxl]of byte;
l,i,j,k,t,x:byte;
begin
repeat
l:=0;
while not eoln do begin
read(s[l+1]);
if (s[l]='(') and (s[l+1]=')') or (s[l]='[') and (s[l+1]=']') then dec(l) else inc(l);
end;
readln;
if l=0 then begin writeln(0);continue;end;
for i:=1 to l do f[i,i]:=1;
for k:=1 to l-1 do
for i:=1 to l-k do begin
j:=i+k;
if (s[i]='(') and (s[j]=')') or (s[i]='[') and (s[j]=']') then f[i,j]:=f[i+1,j-1] else f[i,j]:=255;
for x:=i to j-1 do begin
t:=f[i,x]+f[x+1,j];if t<f[i,j] then f[i,j]:=t;
end;
end;
writeln(f[1,l]);
until eof;//Caution! Empty string exists in input!
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?