不难想到是一个布尔型dp,
不难想到用f[i,j,k]表示区间[i,j]能否变为字母k
不难想到对于f[i,j,k],拆[i,j]成两个区间,然后穷举k的每一个变换来判断
感觉记忆化搜索写的比较顺,就写了记忆化
const a:array[..] of char=('W','I','N','G'); var b:array[..] of longint;
f:array[..,..,..] of integer;
w:array[..,..] of longint;
c:array[..] of longint;
l,i,j,k,e,n,m,p:longint;
flag:boolean;
s:string; function exc(x:char):longint;
begin
if x='W' then exit()
else if x='I' then exit()
else if x='N' then exit()
else if x='G' then exit();
end; function search(l,r,k:longint):integer;
var i,j,x1,x2:longint;
begin
if f[l,r,k]<> then exit(f[l,r,k]);
if l=r then
begin
f[l,l,b[l]]:=;
if k=b[l] then exit()
else begin
f[l,l,k]:=-;
exit(-);
end;
end;
for i:= to c[k] do
begin
x1:=(w[k,i]-) div +;
x2:=(w[k,i]-) mod +;
for j:=l to r- do
begin
if (search(l,j,x1)=) and (search(j+,r,x2)=) then
begin
f[l,r,k]:=;
exit();
end;
end;
end;
f[l,r,k]:=-;
exit(-);
end; begin
for i:= to do
read(c[i]);
readln;
for i:= to do
for j:= to c[i] do
begin
readln(s);
p:=(exc(s[])-)*+exc(s[]);
w[i,j]:=p;
end; readln(s);
n:=length(s); for i:= to n do
b[i]:=exc(s[i]); flag:=false;
for i:= to do
if search(,n,i)= then
begin
write(a[i]);
flag:=true;
end;
if not flag then writeln('The name is wrong!') else writeln;
end.