I hope this helps you . Let res0[n] be the number of ways to reach n steps without using a 3step, and let res1[n] be the number of ways to reach n steps after having used a 3step. res0[i] and res1[i] are easily calculated from the previous values, in a manner similar to your existing code.
Boards Message : 
You Must Login
Or Sign Up
to Add Your Comments . 
Share :
Tags :
Count the total number ways to reach the nth stair using step 1 ,
2 or 3 but the step 3 can be taken only once ,
Count ,
total ,
number ,
ways ,
reach ,
stair ,
using ,
step ,
step ,
taken ,
only ,
once ,

Count Number of ways to reach Nth step using steps of lengths 1,2,3,4,......m.(where m<=n)
Date : March 29 2020, 07:55 AM
seems to work fine Your inner loop adds res[i1] + res[i2] + ... + res[im] to the result. Let s be the sum of the first i elements in res. Then you can simply add s[i1]  s[im1] to the result. ll countWays_(ll n, ll m){
ll res[n];
res[0] = 1; res[1] = 1;
s[0] = 1; s[1] = 2;
for (ll i=2; i<n; i++)
{
if (i <= m)
res[i] = s[i1] % MOD;
else
res[i] = (s[i1]  s[i  m  1] + MOD) % MOD;
s[i] = (s[i1] + res[i]) % MOD;
}
return res[n1];
}

Trying to understand lists in recursive ways step by step
Tag : prolog , By : user152423
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'll help you through your first example. This should give you enough information to tackle the second on your own... Here's your predicate: concatenar([], Xs, Xs).
concatenar([XXs], Ys, [XZs]) : concatenar(Xs, Ys, Zs).
? concatenar([a,b,c], [x,y,z], L).

How to interpret code for counting ways to reach the n’th stair?
Date : March 29 2020, 07:55 AM
it helps some times I am trying to interpret this code from geeksforgeeks: , Check it out like this: # Python 3
def fib(n):
print(f'Fib: {n}')
if n <= 1:
print('End')
return n
else:
print(f'Send: {n1} and {n2}')
return fib(n1) + fib(n2)
def countWays(s):
return fib(s + 1)
s = 4
print("Number of ways = ")
print(countWays(s))
Fib: 5 # A
Send: 4 and 3 # A.B and A.C
Fib: 4 # A.B
Send: 3 and 2 # A.B.1 and A.B.2
Fib: 3 # A.B.1
Send: 2 and 1 # A.B.1.1 and A.B.1.2
Fib: 2 # A.B.1.1
Send: 1 and 0 # A.B.1.1.1 and A.B.1.1.2
Fib: 1 # A.B.1.1.1
End # (END) A.B.1.1.1 > 1
Fib: 0 # A.B.1.1.2
End # (END) A.B.1.1.2 > 0
Fib: 1 # A.B.1.2
End # (END) A.B.1.2 > 1
Fib: 2 # A.B.2
Send: 1 and 0 # A.B.2.1 and A.B.2.2
Fib: 1 # A.B.2.1
End # (END) A.B.2.1 > 1
Fib: 0 # A.B.2.2
End # (END) A.B.2.2 > 0
Fib: 3 # A.C
Send: 2 and 1 # A.C.1 and A.C.2
Fib: 2 # A.C.1
Send: 1 and 0 # A.C.1.1 and A.C.1.2
Fib: 1 # A.C.1.1
End # (END) A.C.1.1 > 1
Fib: 0 # A.C.1.2
End # (END) A.C.1.2 > 0
Fib: 1 # A.C.2
End # (END) A.C.2 > 1
5 # 1 + 0 + 1 + 1 + 0 + 1 + 0 + 1
>>> print(fib(5))
Fib: 5
Send: 4 and 3
Fib: 4
...
Fib: 1
End
5

Count ways to reach the 4th stair using step 1, 2 or 3
Tag : java , By : user186876
Date : March 29 2020, 07:55 AM
will be helpful for those in need Your for loop starts with i = 3, but you already filled in res[3]. That is not a problem if the number of ways to reach 3 would be the same as in your hardcoded value arr[3] = 4;, but it is not. Indeed, you never have set res[0] to 1, and therefore, it will calculate res[3] = res[2] + res[1] + res[0] as 3, not 4. public static void main(String[] args) {
int n = 46;
int [] arr = new int[n+1];
arr[0] = 1;
arr[1] = 1;
arr[2] = 2;
arr[3] = 4;
for(int i = 3; i < n; i++){
arr[i]= arr[i1]+arr[i2]+arr[i3];
}
System.out.println(arr[n]);
}

Print ways to reach the n’th stair
Date : March 29 2020, 07:55 AM

