You’re not currently using bit masking at all in any way that I understand the term.
You currently build a string of binary digits from the check vector, and then convert that string to an integer. Slow.
The power of bit masking is that it’s fast to test, set and clear bits in an integer type.
So imagine that instead of passing the check vector, you passed a single integer where each bit of that integer contained the same information as an element of the check vector?
so if the old check is set, then bit 0 is set in its replacement? Capiche?
if(v[i][j]==1 && check[j]!=1)
if(v[i][j]==1 && (check & (1 << j)) == 0)
int sum=findans(v,check | (1 << j),cnt+1,i-1,v.size()-1,dp);
and since you know there are a max of 20 students, you can initialise the DP array with
(1 << 20) -1
elements instead of 10000000.
One further comment:
if(dp[value]!=-1 && value!=-1)
These tests are the wrong way around. You need to ensure value is valid before using it to access the array.