Cod sursa(job #135713)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 14 februarie 2008 10:31:57
Problema Diamant Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.08 kb
 const
   lim=44100;
   base=10000;
 var
   r,c,l,k,i,j,n,m,x:integer;
   a:array[0..1,-lim..lim] of longint;

 begin
   assign(input,'diamant.in');
   reset(input);
   readln(n,m,x);
   close(input);
   l:=0;
   r:=0; c:=1;
   a[r,0]:=1;
   for i:=1 to n do
     for j:=1 to m do
     begin
       for k:=-l to l do
       begin
         a[r,k]:=a[r,k] mod base;
         if a[r,k]>0 then
         begin
           inc(a[c,k+i*j],a[r,k]);
           {if a[c,k+i*j]>=base then dec(a[c,k+i*j],base);}
           inc(a[c,k-i*j],a[r,k]);
           {if a[c,k-i*j]>=base then dec(a[c,k-i*j],base);}
           inc(a[c,k],a[r,k]);
           {if a[c,k]>=base then dec(a[c,k],base);}
         end;
         {a[c,k]:=a[c,k]+a[r,k];}
         a[r,k]:=0;
       end;
       l:=l+i*j;
       r:=1-r;
       c:=1-c;
     end;
   {dec(a[r,0]);}
   if (-lim<=x)and(x<=lim)and(a[r,x]>=base) then a[r,x]:=a[r,x] mod base;
   assign(output,'diamant.out');
   rewrite(output);
   if (-lim<=x) and (x<=lim)
     then writeln(a[r,x])
     else writeln('0');
   close(output);
 end