You are viewing a single comment's thread. Return to all comments →
Recursion function to avoid TLE :
int solve(int n, int index, vector &dp){
if(index == n){ return 1; } if(index > n){ return 0; } if(dp[index]!=-1){ return dp[index]; } return dp[index] = solve(n,index+1, dp)+solve(n,index+2, dp)+solve(n,index+3, dp);
}
int stepPerms(int n) { vectordp(n+1,-1); int ans = solve(n, 0, dp) % mod;
return ans;
Seems like cookies are disabled on this browser, please enable them to open this website
Recursion: Davis' Staircase
You are viewing a single comment's thread. Return to all comments →
Recursion function to avoid TLE :
int solve(int n, int index, vector &dp){
}
int stepPerms(int n) { vectordp(n+1,-1); int ans = solve(n, 0, dp) % mod;
}