讨论 / 为什么WA:60 最后四组不过
moonnight1228 2011-10-29 14:58:00
点我顶贴 收藏 删除
var

n,i:longint;

a,b,c,s:string;

ch:char;

ok:boolean;

bool:array[1..26]of boolean;

ans,used:array['A'..'Z']of longint;

procedure trys(lie,hang,up:longint);

var

i,j,k:longint;

begin

if lie>n then

begin

if up<=0 then

begin

ok:=true;

ans:=used;

end;

exit;

end;

if ok then exit;

case hang of

1:begin

if used[a[lie]]=-1 then

begin

for i:=0 to n-1 do

if not bool[i] then

begin

bool[i]:=true;

used[a[lie]]:=i;

trys(lie,2,up);

bool[i]:=false;

used[a[lie]]:=-1;

end;

end

else trys(lie,2,up);

end;

2:begin

if used[b[lie]]=-1 then

begin

for i:=0 to n-1 do

if not bool[i] then

begin

bool[i]:=true;

used[b[lie]]:=i;

trys(lie,3,up);

bool[i]:=false;

used[b[lie]]:=-1;

end;

end

else trys(lie,3,up);

end;

3:begin

k:=used[a[lie]]+used[b[lie]]+up;

j:=0;

j:=k div n;

k:=k-j*n;

if used[c[lie]]=k then

trys(lie+1,1,j)

else if (used[c[lie]]=-1) and (not bool[k]) then

begin

used[c[lie]]:=k;

bool[k]:=true;

trys(lie+1,1,j);

used[c[lie]]:=-1;

bool[k]:=false;

end;

end;

end;

end;

begin

readln(n);

readln(a);

readln(b);

readln(c);

s:='';

for i:=1 to n do

s:=a[i]+s;

a:=s;

s:='';

for i:=1 to n do

s:=b[i]+s;

b:=s;

s:='';

for i:=1 to n do

s:=c[i]+s;

c:=s;

for ch:='A' to 'Z' do

used[ch]:=-1;

fillchar(bool,sizeof(bool),false);

ok:=false;

trys(1,1,0);//第一个,第一行,进位为多少

for i:=0 to n-2 do

write(ans[chr(i+65)],' ');

writeln(ans[chr(n-1+65)]);

end.

#1 Natter@2011-08-27 21:07:00
回复 删除
你先说这是哪道题

你先说这是哪道题

#2 zhouyi@2011-10-29 14:58:00
回复 删除
高精度
查看更多回复
提交回复