My answer geting wrong only for n=43

count number of binary strings

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[106][2];
const int mod = (1e9 + 7);

ll func(ll n,ll prev)
{
if(n==0)
return 1;
if(n<0)
return 0;

 if(dp[n][prev]!=-1)
 return dp[n][prev];

if(prev==0)
{
	dp[n][prev]=(func(n-1,1)%mod + func(n-1,0)%mod)%mod;
}
else
{
	dp[n][prev] = func(n-1,0)%mod;
}

return dp[n][prev];

}

int main()
{
ll t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
memset(dp,-1,sizeof(dp));
ll ans=func(n-1,0)+func(n-1,1);
cout<<ans<<endl;

}

}

@reddevil
hello saurabh,
your code is correct .just remove mod from ur code (In question it is not asked to take modulo)

@reddevil
hello saurabh,
if ur doubt is resolved then pls mark it as resolved

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.