Cod sursa(job #116398)

Utilizator savimSerban Andrei Stan savim Data 18 decembrie 2007 15:56:04
Problema Diamant Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.08 kb
var i,j,n,m,x,y,k,s:longint;
    a,b:array[-44100..44100] of integer;
    f1,f2:text;
begin
    assign(f1,'diamant.in');
    assign(f2,'diamant.out');
    reset(f1);
    rewrite(f2);

    readln(f1,n,m,s);

    if (s>44100) or (s<-44100) then
    begin
        writeln(f2,0);
        close(f1);
        close(f2);
        halt;
    end;
    a[-1]:=1;
    a[0]:=1;
    a[1]:=1;
    for i:=1 to n do
        for j:=1 to m do
        begin
            if (i=n) and (j=m) then break;
            for k:=-44100 to 44100 do
            if (a[k]<>0) then
            begin
                x:=i;
                y:=j;
                if (y<m) then y:=y+1
                else begin inc(x);y:=1;end;
                b[k-x*y]:=(b[k-x*y]+a[k]) mod 10000;
                b[k]:=(b[k]+a[k]) mod 10000;
                b[k+x*y]:=(b[k+x*y]+a[k]) mod 10000;
            end;
            for k:=-44100 to 44100 do
            begin
                a[k]:=b[k];
                b[k]:=0;
            end;
        end;
    writeln(f2,a[s]);
    close(f1);
    close(f2);
end.