Freinds Pairing Problem

My code is giving wrong answer .Why??
code link is https://ide.codingblocks.com/s/237060

hello @Bhawna
for n=1 u are accessing dp[2] which is wrong.
handle that case ie n =1 then print 1.and continue;

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
ll dp[n+1];
memset(dp,0,sizeof(dp));
if(n==1||n==2)
{
cout<<n<<endl;
continue;
}
for(ll p=3;p<=n;p++)
{
dp[p]=dp[p-1]+((p-1)*dp[p-2]);
}
cout<<dp[n]<<endl;
}
}
Still it is giving wrong answer

ur code is correct .
maybe the issue is with online judge.

kindly look into this matter as soon as possible as it is consuming a lot of our time on checking same code again and again .I have also found this same for other questions too.

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.