#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int dp[n+1];
dp[0]=0;
dp[1]=2;
dp[2]=3;
dp[3]=5;
for(int i=4;i<=n;i++)
{
dp[i]=dp[i-1]+dp[i-2];
}
cout<<dp[n]<<endl;;
}
return 0;
}
Not able to pass all test case
Dp[0] & Dp[1] should be 1, instead of int use long long int as test cases are very high in number. Do this and it might get accepted.
dp[1] is to be 2 or 1
Oh yes, Dp[0] should be 1 & Dp[1] should be 2.
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.