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 1009. K-based Numbers

help,why I got WA3?
Posted by grey 27 May 2004 16:10
program fa;
var
  r:longint;
  i,j,k,n:longint;
function c(a,b:longint):longint;
var
  i1,q:longint;
begin
if (b=0)or(a=b)
  then begin
    c:=1;
    exit;
  end;
q:=1;
  for i1:=a downto a-b+1 do
    begin
      q:=q*i1 div (a-i1+1);
    end;
  c:=q;
end;
begin
  r:=0;
  read(n);
  read(k);
  for i:=0 to n div 2 do
    begin
      r:=r+(c(n-i,i))*trunc(exp((n-i)*ln(k-1)));
    end;
    writeln(r);
end.
Re: help,why I got WA3?
Posted by marina_ufa 27 May 2004 18:55
Your algorithm is wrong.
This is correct dinamic

a[0] := 1; a[1] := k-1;
a[i] := (k-1)*(a[i-1] + a[i-2]);

answer - a[n].
Re: help,why I got WA3?
Posted by grey 1 Jun 2004 14:29
thank you!!
you are quite right.but can you give me some date that my program can't work out? becase i try it many times,and can't  find this data.