Cod sursa(job #35094)

Utilizator andradaqAndrada Georgescu andradaq Data 21 martie 2007 20:22:18
Problema Diamant Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.73 kb
var f:text;
    c1,cn:array[-64410..64410] of integer;
    v:array[1..400] of integer;
    smax,n,m,i,j,k,x,p:longint;


begin
assign(f,'diamant.in'); reset(f);
readln(f,n,m,x);
smax:=0;
p:=0;
for i:=1 to n do
 for j:=1 to m do
  begin
  inc(p);
  v[p]:=i*j;
  smax:=smax+v[p];
  end;
close(f);
assign(f,'diamant.out'); rewrite(f);
if (x<-smax) or (smax<x) then writeln(f,0)
 else
  begin
  c1[-1]:=1;
  c1[0]:=1;
  c1[1]:=1;
  for k:=2 to p do
  begin
   fillchar(cn,sizeof(cn),0);
   for j:=-smax to smax do
    if c1[j]>0 then
    begin
     cn[j]:=cn[j]+c1[j];
     cn[j-v[k]]:=cn[j-v[k]]+c1[j];
     cn[j+v[k]]:=cn[j+v[k]]+c1[j];
     end;
  c1:=cn;
  end;
 writeln(f,cn[x]);
 end;
close(f);
end.