Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//Assuming that there are 20 friends
int dp[1<<20][20];
//mask=frinds I already visited
//at=last visited friend
int Dp(int mask, int at)
//I used reference. It helps me not
//writing dp[mask] [at] again and again.
int& ret = dp[mask] [at];
//Assume that we initilized dp with -1
if (ret !=-1) return ret;
//initialize ret with infinity
ret = 1000000000;
//n = number of friend
//dist contains distance between every two nodes
for (int i = 0; i<n; i++)
inf (!(mask & (1<<i)))
//mask | (1<<i) turns on i th bit in mask.
ret = MIN(re,
DP(mask | (1<<i), i) + dist[at][i]);
return ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.