Created
June 5, 2018 08:42
-
-
Save shameemreza/c2abd20513765250081ccae806ae6ab7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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