anybody, please help me in figuring out the bitmasking used in candles counting problem on hackerrank (inclusion-exclusion principle approach) problem I am not able to clearly get what's being written in the editorial code. I know inclusion-exclusion principle but I am not able to clearly visualize the code thanks in advance.
int res = 0;
for(int mask = 0; mask < (1 << K); mask ++){
memset(ft, 0, sizeof ft);
int tmp = 0;
for(int i = 0; i < N; i++){
if((mask >> (C[i] - 1)) & 1){
dp[i] = 1 + query(H[i] - 1);
madd(tmp, dp[i]);
update(H[i], dp[i]);
}
}
if(__builtin_popcount(mask) % 2 == K % 2){
madd(res, tmp);
} else {
madd(res, mod - tmp);
}
}
assertrange(res, 0, mod - 1);
printf("%d\n", res);