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

I don't understaind the algo
Posted by Aresakaoni 9 Sep 2006 00:45
please i don't understaind .

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

for n=2 and k = 10 the answer is 90 allright,but ,from my point of view for n=2 and k = 9 the right answer is 99 ,2 digits number 9 based, but the algo show 72 , I've AC but, is this the right algo?.

sorry but my english is too bad .


Re: I don't understaind the algo
Posted by KIRILL 11 Sep 2006 23:47
a[2] = k*k-k
This is all numbers from 10 to 88 (if k = 9 and n = 2)
Re: I don't understaind the algo
Posted by FireHeart 25 May 2007 06:56
not all, the number 19, 29, 39, 49 .. 79 is not allowed !
Re: I don't understaind the algo
Posted by Peter Ivanov 19 Jul 2007 03:08
FireHeart: you don't have the digit '9' when k=9
Re: I don't understaind the algo
Posted by mathfrog 22 Aug 2007 21:41
 that is a CLASSICAL math problem , i didnt realize it till i got 6 WAs. we fix the first number to be nonzero,and let
f(n) be all the correct numbers . suppose the second digit is not zero ,we have f(n-1) correct ways. otherwise,we have f(n-2) ways. by addition law ,we have
f(n)=(k-1)(f(n-1)+f(n-2)) . the idea is very classical and we should remember it all the time .
Re: I don't understaind the algo
Posted by Boyan Lazov 22 Jul 2008 15:28
It is a classical combinatorial problem. You can solve it with the elegant recurrent relation, but figuring it out how to do it yourself is more valuable. I did it using some combinatoric (i.e.: the number we seek is sum of the K-based numbers with N digits who have exactly X zeroes (i.e. K-X free digits from 1..K-1) and don't have adjacent zeroes (sometimes this is zero, when X > N-X). If f(N,K,X) is this number, we seek sum(X=0 to N-1) f(N,K,X) (we can lower the upper bound X-1 but there's no need if you compute f properly)

Edited by author 22.07.2008 15:30