What's wrong with test#9
Послано
Arthas 30 май 2010 08:41
My program gives a wrong answer with test#9,but I don't know where the mistake is,please help me correct it
program ural1002;
var
f,w:array[0..100,0..100]of longint;
s:string;
n:longint;
ans:longint;
c,cc:array[1..50000]of string[51];
list:array['0'..'9',1..50,0..500]of longint;
const
func:array['a'..'z']of char
=('2','2','2','3','3','3','4','4','1','1','5','5',
'6','6','0','7','0','7','7','8','8','8','9','9','9','0');
procedure init;
var
i,j,k,l:longint;ss:string[51];
begin
readln(s);
if s='-1' then halt;
readln(n);
for i:=1 to n do
begin
readln(c[i]);
cc[i]:=c[i];
end;
fillchar(list,sizeof(list),0);
for i:=1 to n do
begin
ss:='';
for j:=1 to length(c[i]) do ss:=ss+func[c[i,j]];
c[i]:=ss;
inc(list[c[i,1],length(c[i]),0]);
list[c[i,1],length(c[i]),list[c[i,1],length(c[i]),0]]:=i;
end;
for i:=0 to length(s) do for j:=0 to length(s) do
w[i,j]:=i;
for i:=0 to length(s) do for j:=0 to length(s) do if i=j then
f[i,j]:=0 else f[i,j]:=n+1;
for i:=1 to length(s) do
for j:=1 to 50 do
for k:=1 to list[s[i],j,0] do
if copy(s,i,j)=c[list[s[i],j,k]] then
begin
f[i-1,i+j-1]:=1;
w[i-1,i+j-1]:=-list[s[i],j,k];
end;
end;
function dp:longint;
var
i,j,k:longint;
begin
for k:=0 to length(s) do
for i:=0 to k do
for j:=k to length(s) do
if f[i,k]+f[k,j]<f[i,j] then
begin
f[i,j]:=f[i,k]+f[k,j];
w[i,j]:=k;
end;
dp:=f[0,length(s)];
end;
procedure print(l,r:longint);
begin
if w[l,r]<0 then
begin
write(cc[-w[l,r]]);
if r<length(s) then write(' ')else writeln;
exit;
end
else
begin
print(l,w[l,r]);
print(w[l,r],r);
end;
end;
begin
while true do
begin
init;
ans:=dp;
if ans<=n then
print(0,length(s))
else
writeln('No solution.');
end;
end.