ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1009. K-ичные числа

I don't understaind the algo
Послано Aresakaoni 9 сен 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
Послано KIRILL 11 сен 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
Послано FireHeart 25 май 2007 06:56
not all, the number 19, 29, 39, 49 .. 79 is not allowed !
Re: I don't understaind the algo
Послано Peter Ivanov 19 июл 2007 03:08
FireHeart: you don't have the digit '9' when k=9
Re: I don't understaind the algo
Послано mathfrog 22 авг 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
Послано Boyan Lazov 22 июл 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