Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Bitonic Traveling Salesman Problem (Bitonic TSP)

For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:

Visit the points according to the following steps:

It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point).

Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.

Through the processes 1. 2., the tour must visit each point at least once.

Input

The input data is given in the following format:

$N$

$x_1$ $y_1$

$x_2$ $y_2$

...

$x_N$ $y_N$

Constraints

$2 \leq N \leq 1000$

$-1000 \leq x_i, y_i \leq 1000$

$x_i$ differ from each other

The given points are already sorted by x-coordinates

Output

Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.

Sample Input 1

3
0 0
1 1
2 0

Sample Output 1

4.82842712

Sample Input 2

4
0 1
1 2
2 0
3 1

Sample Output 2

7.30056308

Sample Input 3

5
0 0
1 2
2 1
3 2
4 0

Sample Output 3

10.94427191

Solution in JAVA (judge verdict: Wrong Answer)

import java.io.*;
import java.util.Scanner;
 
public class Main {
    public static double btsp(int[] x, int[] y) {
        int n = x.length;

        double[][] aux = new double[n][n];
        for (int j = 1; j < n; j++) {
            aux[0][j] = aux[0][j-1] + distance(x[j-1], y[j-1], x[j], y[j]);
        }

        for (int i = 1; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) {
                    aux[i][j] = aux[i-1][j] + distance(x[i-1], y[i-1], x[j], y[j]);
                } else if (i == j - 1) {
                    double min = Double.POSITIVE_INFINITY;
                    for (int k = 0; k < j; k++) {
                        min = Math.min(min, aux[k][j-1] + distance(x[k], y[k], x[j], y[j]));
                    }
                    aux[i][j] = min;
                } else {
                    aux[i][j] = aux[i][j-1] + distance(x[j-1], y[j-1], x[j], y[j]);
                }
            }
        }
        return aux[n-1][n-1];
    }

    public static double distance(int x1, int y1, int x2, int y2) {
        return Math.sqrt((x1-x2)^2 + (y1-y2)^2);
    }

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x[] = new int[n];
        int y[] = new int[n];

        for(int i = 0; i < n; i++) {           
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        System.out.println(btsp(x, y));
    }
}