Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя nilsilu95

Автор nilsilu95, 9 лет назад, По-английски
Find how many N digit crazy numbers exist such that the difference between the adjacent digits of the number is exactly one. Crazy numbers have  the difference between the adjacent digits of that number is exactly one.
For N = 3, crazy numbers are 123 , 434 , 567 etc. Numbers like 576, 453 etc. are not considered crazy numbers.
Find out how many crazy numbers exist containing exactly N digits modulo  10^9+7.

For N=1, crazy numbers are 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 .
For N=2, crazy numbers are 10 , 12 , 21 , 23 , 32 , 34 , 43 , 45 , 54 , 56 , 65 , 67 , 76 , 78 , 87 , 89 , 98.

my approach is

f(num,sz)=total crazy numbers  of sz={1,2,3, ..upto n} and num={ 1,2,3,4,5,6,7,8,9}

base case is f(num,1)=1 // crazy numbers of length 1 is 1 for each num
f(num,sz)=f(num-1,sz-1)+f(num+1,sz-1) //for num= 1 2 3 4 5 6 7 8  
                                      //as each num except 9 has 2 states ,,1->0 , 1->2 but 9->8 only
         =f(num-1,sz-1) for num=9  
Then required ans is f(1,n)+f(2,n)+..f(9,n) .for n=1 we add special case 0


Is my approach correct?Pls help 

http://ideone.com/MFs8ou

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You forgot to add digit 0 which is special case and this might work.

But yet again — why ask such questions? Why don't submit that code and see whether your approach is correct.