Cod sursa(job #27428)

Utilizator andradaqAndrada Georgescu andradaq Data 6 martie 2007 14:04:43
Problema 1-sir Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.06 kb
const prim=194767;
var f:text;
    smax,s,total:longint;
    a:array[0..256,0..256] of integer;
    b:array[0..256,0..256] of word;
    l,c,n,i,j:byte;

function suma(s:longint;l,c:byte):longint;
var s1,s2:longint;
    i:byte;
begin
if (l=0) and (c=0) then if s=0 then suma:=1
                               else suma:=0
 else
  begin
  s1:=0;
  s2:=0;
  if c-1>=0 then s1:=suma(s-a[l,c],l,c-1);
  if l-1>=0 then s2:=suma(s-a[l,c],l-1,c);
  suma:=(s1+s2) mod prim;
  end;
end;

begin
assign(f,'1-sir.in'); reset(F);
readln(f,n,s);
close(F);
assign(f,'1-sir.out');
rewrite(F);
smax:= (n*(n-1)) div 2;
if (s<-smax) or (smax<s) or (smax mod 2 - s mod 2 <>0) then writeln(f,0)
else if (abs(s)=smax) then writeln(f,1)
 else
  begin

a[0,0]:=0;
for i:=1 to n do
 begin
 a[0,i]:=i;
 a[i,0]:=-i;
 end;
for i:=1 to n-1 do
 for j:=1 to i do
  begin
   l:=i-j+1;
   c:=j;
   a[l,c]:=(a[l-1,c]+a[l,c-1])div 2;
  end;
total:=0;
for i:=1 to n do
 total:=(total+suma(s,i-1,n-i)) mod prim;
if total>0 then write(f,total,' ');
end;
close(F);
end.