ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1114. Boxes

Algorithmus_UA(algorithmus@univ.kiev.ua) I go WA!!! Help me plese give some tests! // Problem 1114. Boxes 31 Oct 2002 02:56
type
 long = record
              a:array[1..250]of byte;
              l:byte;
        end;
procedure add(var a,b:long);
var l,c,k,i:byte;
begin
  k:=0;
  if a.l>b.l then l:=a.l else l:=b.l;
  i:=1;
  for i:=1 to l do
  begin
    c:=a.a[i];
    a.a[i]:=(c+b.a[i]+k)mod 10;
    k:=(c+b.a[i]+k)div 10;
  end;
  a.l:=i;
  if k<>0 then
  begin
    inc(a.l);
    a.a[a.l]:=K;
  end;
end;

procedure mul_i(var a:long;b:longint);
var k:longint;c,i:byte;
begin
  k:=0;
  i:=1;
  for i:=1 to a.l do
  begin
    c:=a.a[i];
    a.a[i]:=(c*b+k)mod 10;
    k:=(c*b+k)div 10;
  end;
  a.l:=i;
  while k<>0 do
  begin
    inc(a.l);
    a.a[a.l]:=K mod 10;
    k:=k div 10;
  end;
end;

procedure mul(var a,b:long);
var tmp,_a:long;
    i,j:byte;
begin
  fillchar(tmp,sizeof(tmp),0);
  for i:=1 to b.l do
  begin
    _a:=a;
    mul_i(_a,b.a[i]);
    for j:=_a.l downto 1 do _a.a[j+i-1]:=_a.a[j];
    for j:=1 to i-1 do _a.a[j]:=0;
    _a.l:=_a.l+i-1;
    add(tmp,_a);
  end;
{  i:=tmp.l;
  for i:=tmp.l downto 1 do if tmp.a[i]<> 0 then break;
  tmp.l:=i;}
  a:=tmp;
end;

var c:array[0..15]of extended;
    N,A,B,MMM:longint;
    i,j:integer;
    tmp:extended;
function cnk(N,K:integer):longint;
var s:longint;
    i:integer;
begin
  s:=1;
  for i:=K+1 to N do
  s:=s*i div (i-K);
  cnk:=s;
end;

var _a,_b:long;
begin
{  cnk(20,10);}
{  assign(input,'1114.dat');reset(input);}
  readln(N,A,B);
  if A>B then mmm:=A else mmm:=B;
  c[0]:=1;
  for i:=1 to mmm do
  begin
    {for j:=i-1 downto 0 do} c[i]:=c[i]+c[i-1];
    for j:=1 to i do
    begin
      c[i]:=c[i]+cnk(N,j)*cnk(i-1,j-1);
    end;
  end;
  tmp:=c[a];
  for i:=1 to 25 do
  begin
    _a.a[i]:=trunc(tmp-int(tmp/10)*10);
    tmp:=int(tmp/10);
  end;
  i:=25;
  for i:=25 downto 1 do if _a.a[i]<>0 then break;
  _a.l:=i;
  tmp:=c[b];
  for i:=1 to 25 do begin _b.a[i]:=trunc(tmp-int(tmp/10)*10);tmp:=int
(tmp/10);end;
  i:=25;
  for i:=25 downto 1 do if _b.a[i]<>0 then break;
  _b.l:=i;
  mul(_a,_b);
  for i:=_a.l downto 1 do write(_a.a[i]);
  writeln;
{  writeln(c[A]*c[B]:0:0);}
end.