Cod sursa(job #121444)

Utilizator raduzerRadu Zernoveanu raduzer Data 8 ianuarie 2008 19:17:27
Problema Diamant Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.24 kb
var v,t:array[-45000..45000]of longint;
    x:array[0..1000]of longint;
    i,j,n,m,c,s:longint;

begin
     assign(input,'diamant.in');
     reset(input);
     assign(output,'diamant.out');
     rewrite(output);
     readln(n,m,c);
     for i:=1 to n do
     begin
          for j:=1 to m do
          begin
               s:=s+i*j;
               inc(x[0]);
               x[x[0]]:=i*j;
          end;
     end;
     if (c>s)or (c<-s) then
     begin
          writeln(0);
          close(output);
          halt;
     end;

     v[0]:=1;
     t[0]:=1;

     for i:=1 to x[0] do
     begin
          for j:=-s to s do
          begin
               if (t[j]<>0) then
               begin
                    if (x[i]+j<=s)and(x[i]+j>=-s) then
                    begin
                         inc(v[x[i]+j],t[j]);
                         v[x[i]+j]:=v[x[i]+j] mod 10000;
                    end;
                    if (-x[i]+j<=s)and(-x[i]+j>=-s) then
                    begin
                         inc(v[-x[i]+j],t[j]);
                         v[-x[i]+j]:=v[-x[i]+j] mod 10000;
                    end;
               end;
          end;
          t:=v;
     end;
     writeln(v[c] mod 10000);
close(output);
end.