-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountNumberOfHops.cpp
More file actions
53 lines (41 loc) · 941 Bytes
/
countNumberOfHops.cpp
File metadata and controls
53 lines (41 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
//Function to count the number of ways in which frog can reach the top.
long long countWays(int n)
{
long long int dp[n+1];
dp[1]=1;
dp[2]=2;
dp[3]=4;
for(int i=4;i<=n;i++)
{
dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
dp[i]%=1000000007;
}
return dp[n]%1000000007;
}
};
// { Driver Code Starts.
int main()
{
//taking testcases
//A frog jumps either 1, 2, or 3 steps to go to the top.
//In how many ways can it reach the top. As the answer will be large find the answer modulo 1000000007.
int t;
cin >> t;
while(t--)
{
//taking number of steps in stair
int n;
cin>>n;
Solution ob;
//calling function countWays()
cout << ob.countWays(n) << endl;
}
return 0;
}
// } Driver Code Ends