Cod sursa(job #34855)

Utilizator andradaqAndrada Georgescu andradaq Data 21 martie 2007 15:53:00
Problema Diamant Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.98 kb
var c1,cn,cu:array[0..44100] of longword;
    s,x,smax:longint;
    n,m,i,j,k:byte;
    st:array[1..21] of integer;
    f:text;

procedure back;
begin
while k>0 do
begin
if k=m+1 then
 begin
 s:=0;
 for i:=1 to m do s:=s+st[i]*i;
 if s>=0 then c1[s]:=(longword(c1[s])+longword(1)) mod 10000;
 dec(k);
 end
 else
  if st[k]<1 then begin inc(st[k]); st[k+1]:=-2; inc(k); end
             else dec(k);
end;
end;

begin
assign(f,'diamant.in'); reset(f);
readln(f,n,m,x);
smax:=0;
for i:=1 to n do
 for j:=1 to n do smax:=smax+i*j;
close(f);

assign(f,'diamant.out'); rewrite(f);
if x>smax then writeln(f,0) else
begin
fillchar(c1,sizeof(c1),0);
s:=(m*(m+1)) div 2;
st[1]:=-2;
k:=1;

back;

{for i:=0 to s do write(c1[i],' ');}

cn:=c1;
for i:=2 to n do
 begin
 fillchar(cu,sizeof(cu),0);
   for j:=0 to smax do
    for k:= 0 to smax do
      cu[i*j+k]:=(cu[i*j+k]+(c1[j]*cn[k])mod 1000) mod 10000;
 cn:=cu;
 end;

writeln(f,cu[x]);
end;
close(f)
end.