Skip to content

Instantly share code, notes, and snippets.

void dijkstra() {
int[] dist = new int[n + 1];
boolean[] visited = new boolean[n + 1];
for (int source = 0; source < k + 1; source++) {
arrays.fill(dist, INFINITY);
arrays.fill(visited, false);
dist[list[source]] = 0;
for (int t = 0; t < n; t++) {
int min = INFINITY;
@z11i
z11i / DP_TSP.java
Last active November 11, 2015 03:02
memo = new int[V][1 << V];
T = new int[V][V]; // adjacency matrix
int min_dist_from_0 = DP_TSP(0, 1);
int DP_TSP(int u, int m) { // m is visited mask (bitmask)
if (m == ((1 << V) - 1)) // all 1, all vertices have been visited
return T[u][0]; // no choice, return to vertex 0
if (memo[u][m] != -1) // computed before
return memo[u][m];