![]()
对于这道题,如果把它理解为一个拼图游戏,其实很简单,代码如下:
var
f:array[1..10,'A'..'Z']of longint;
n,c,ans,i,j,k,l:longint; s:string;
begin
assign(input,'wing.in'); reset(input);
assign(output,'wing.out'); rewrite(output);
readln(n,c);
for i:=1 to c do
begin
read(j,s);
delete(s,1,1);
l:=0;
if j=1 then
begin
for k:=1 to n do
begin
if f[k,s[k]]=0 then begin l:=-1; break; end;
if f[k,s[k]]>l then l:=f[k,s[k]];
end;
end
else
begin
inc(ans);
for k:=1 to n do
if f[k,s[k]]=0 then f[k,s[k]]:=ans;
end;
if j=1 then writeln(l);
end;
close(input); close(output);
end.