why we don’t count upto 1 to k why we don’t count ? I want to ask that if I want to calculate the total number of ways to to reach n steps so up to n steps if we need f( n) steps similarly for n-1 we need f( n-1) yes that’s the process but what about 1 to k if f( n) = f( n-1) +f(n-2)+ up to f( n-k ) then why we don’t take 1 to k we should reach up to k also so we should add them with f(n-1) +f(n-2) so the equation should be f(n)= f(n-1)+f(n-2)+ …+f(n-k)+k+k-1+…+3+2+1 why not that why I don’t calculate 1 to k why we calculate up to n-k?
Dynamic programming
@Anusree_Dey
Lets say k = 3
And total steps are 4
and you have calculated ans for 1, 2, 3
At step 4 you have 3 places from where you can come to 4
Which are 3, 2 and 1
So you only add number of ways to reach till n-3 or n-k
You cant reach N from steps less than N-K thats why their contribution is not taken
If your doubt is resolved please close it
why i can’t reach reach n from 1 I can also reach ? why i take till n-k I cant understand why?
why i can’t reach reach n from 1 I can also reach ? why i take till n-k i cant understand why i cant reach n less than n-k ? I can also reach from 1
@Anusree_Dey
K means the max jump you can take
So if k is 3 you’re at 1 you can only go to 2, 3, 4 not any further
i understand that but still i can’t understand why we don’t take 1 to k in contribution?
@Anusree_Dey
If you are at 5 and K is 3
You can reach 5 from 4 3 and 2
Why will you take contribution of 1
then there is total no of ways i SHOULD calculate how i reach 2 ,3 or 4 from 1 why i dont take them i am calculating total no of ways
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.