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 1513. Lemon Tale

Algo to solve
Posted by Tutanhamon 19 Feb 2008 00:51
My algo is
------------------------------------
we take an array[-2..N]
then we do this:
A[-2]:=0
A[-1]:=1
for i:=1 to k do
  a[i]:=2^i

for i:=k to n do
  a[i]:=2*a[i-1]-a[i-2-k]
-------------------------------------
at the end we get a[n]-output number
-------------------------------------
certainly i used long arithmetic and my array is not such simple as in this example: it's only algo


Edited by author 19.03.2008 00:23
Re: Algo to solve
Posted by RASTA 23 Apr 2009 19:15
This algo isn't correct
instead
for i := 1 to k do a[i] := 2^i;
must be
for i := 0 to k do a[i] := 2^i;//may be runtime error
OR
a[0] = 1
for i := 1 to k do a[i] := a[i - 1] * 2;
its works nicely:)

Edited by author 23.04.2009 19:56
Re: Algo to solve
Posted by Oleg Strekalovsky aka OSt [Vologda SPU] 17 Oct 2009 01:41
Special case -
k = 0 then answer is 1