Friends pairing problem wrong answer

#include

using namespace std;

#define ll long long

ll ways(ll n){

ll dp[n+1];

memset(dp,0,sizeof(dp));

dp[1]=1;

dp[0]=1;

for(ll i=2;i<=n;i++){

dp[i]=dp[i-1]+(i-1)*dp[i-2];

}

return dp[n];

}

int main() {

ll t;

cin>>t;

while(t–){

ll n;

cin>>n;

ll ans= ways(n);

cout<<ans;

}

return 0;

}