| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Why I got WA?This is my program.program twofive;
var
a:array['A'..'Y']of longint;
c:array[1..25]of char;
f:array[0..6,0..6,0..6,0..6,0..6]of longint;
b:array[1..5]of longint;
num:array[1..5]of longint;
n:longint;
ch:char;
function mi(i,j:longint):longint;
begin
if i<j then mi:=i else mi:=j;
end;
procedure cal;
var
tot:longint;
begin
tot:=0;
if num[5]+1<=num[4] then tot:=tot+f[num[1],num[2],num[3],num[4],num[5]+1];
if (num[4]<>5)and(num[4]+1<=num[3]) then tot:=tot+f[num[1],num[2],num[3],num[4]+1,num[5]];
if (num[3]<>5)and(num[3]+1<=num[2]) then tot:=tot+f[num[1],num[2],num[3]+1,num[4],num[5]];
if (num[2]<>5)and(num[2]+1<=num[1]) then tot:=tot+f[num[1],num[2]+1,num[3],num[4],num[5]];
if (num[1]<>5) then tot:=tot+f[num[1]+1,num[2],num[3],num[4],num[5]];
f[num[1],num[2],num[3],num[4],num[5]]:=tot;
end;
procedure sou(k,sum,max:longint);
var
i:longint;
begin
if k=5 then begin
if sum<=max then begin num[5]:=sum;cal;end;
end else begin
for i:=mi(max,sum) downto 0 do
begin
num[k]:=i;
sou(k+1,sum-i,i);
num[k]:=0;
end;
end;
end;
procedure main;
var
sum:longint;
begin
fillchar(f,sizeof(f),0);
f[5,5,5,5,5]:=1;
for sum:=24 downto 1 do
sou(1,sum,5);
end;
procedure task1;
var
tot,j:longint;
ch:char;
begin
fillchar(b,sizeof(b),0);
tot:=0;
b[1]:=1;
for ch:='B' to 'X' do
begin
j:=a[ch]-1;
if j>=1 then tot:=tot+f[b[1]+1,b[2],b[3],b[4],b[5]];
if j>=2 then tot:=tot+f[b[1],b[2]+1,b[3],b[4],b[5]];
if j>=3 then tot:=tot+f[b[1],b[2],b[3]+1,b[4],b[5]];
if j>=4 then tot:=tot+f[b[1],b[2],b[3],b[4]+1,b[5]];
inc(b[a[ch]]);
end;
writeln(tot+1);
end;
procedure task2;
var
ch:char;
i,j:longint;
begin
fillchar(b,sizeof(b),0);
b[1]:=1;
a['A']:=1;
for ch:='B' to 'Y' do
begin
j:=5;
if f[b[1]+1,b[2],b[3],b[4],b[5]]>=n then j:=1 else n:=n-f[b[1]+1,b[2],b[3],b[4],b[5]];
if j=5 then if f[b[1],b[2]+1,b[3],b[4],b[5]]>=n then j:=2 else n:=n-f[b[1],b[2]+1,b[3],b[4],b[5]];
if j=5 then if f[b[1],b[2],b[3]+1,b[4],b[5]]>=n then j:=3 else n:=n-f[b[1],b[2],b[3]+1,b[4],b[5]];
if j=5 then if f[b[1],b[2],b[3],b[4]+1,b[5]]>=n then j:=4 else n:=n-f[b[1],b[2],b[3],b[4]+1,b[5]];
a[ch]:=j;
inc(b[j]);
end;
for i:=1 to 5 do
for ch:='A' to 'Y' do
if a[ch]=i then write(ch);
writeln;
end;
procedure init;
var
i,j:longint;
begin
readln(ch);
if ch='W' then begin
for i:=1 to 5 do
for j:=1 to 5 do
begin
read(c[i]);
a[c[i]]:=i;
end;
task1;
end else begin
read(n);
task2;
end;
end;
begin
main;
init;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator