The Ghost Type

Here is the link of the above problem i have been trying. Just want to know where i am going wrong with my this code?
#include<bits/stdc++.h>
using namespace std;
int n;
int getcount(int mask){
if(mask== (1<<(n)-1))
return 1;
int count=0;
for(int i=0;i<n;i++){
if(!mask&(1<<i)){
for(int j=1; j<=n; j++){
if(!mask&(1<<(j-1)) && (i+1)&(j)==(i+1))
if(getcount(mask|(1<<i)))
count++ ;
}
}
}
return count;
}
int main(){

cin>>n;

cout<<getcount(0)<<endl;

return 0;

}
please help me with the above one.

Please indent ur code properly instead of just return 0 too hard to read

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[1<<20];
ll solve(int n){
    int mask=(1<<n)-1;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<mask;i++){
        for(int j=0;j<n;j++){
            if((1<<j & i)==0){
                bool flag=false;
                for(int k=0;k<n;k++){
                    if(((j+1)&(k+1))==j+1 && ((1<<k)&i)){
                        flag=true;
                        break;
                    }
                }
                if(flag==false){
                    dp[1<<j|i]+=dp[i];
                }
            }
        }
    }
    return dp[mask];
    
}

Here I am considering masking as whether that number at that position has already been in the sequence or not or not if there is bit is already 1 which is what I am checking on the third loop it means that I considered it initially so the loop will break contributing nothing.