소프트웨어 개발/Java - Basic

임시

늘근이 2016. 4. 4. 22:53

public class TSP2 {
 
 static int MAX = 15;
 static int N = 15;
 static double temp = 9999999;
 static double[][] cache = new double[MAX][1<<MAX];
 
 public static void main(String[] args) {
  
 }
 
 double shortestPath(int here, int visited) {
  
  if(visited == (1<<N)-1) return dist[here][0];
  temp = cache[here][visited];
  if(temp >= 0) return temp;
  temp = 99999999999l;
  
  for (int next = 0; next < N; next++) {
   if(visited && (1<<next)) continue;
   double cand = dist[here][next] + shortestPath(next, visited + (1<<next));
   temp = Math.min(temp, cand);
  }
  return temp;
  
 }
}