// Solution to Orienteering // Author: Thomas Beuman // Time complexity: O(n*2^n + n^2*n!/(n/2)!*log(n)) // Memory: O(n^2 + (n/2)!) // Expected result: accepted #include #include using namespace std; const int nmax = 14; long long Dis[nmax][nmax]; long long Trip1[720], Trip2[720]; // array sizes: (ceil(nmax/2-1))! // Considers all permutations of points in subset s as intermediate stops between 0 and p; // stores distances in Trip[] and returns number of permutations int tryallperms (int n, int p, int s, long long Trip[]) { // Base case if (s == 0) { Trip[0] = Dis[0][p]; return 1; } int m = 0, i, k = 0; int Point[nmax/2]; long long d = 0; // Dissect subset for (i = 1; i < n; i++) if (s & (1<= 0;) { if (Trip1[i] + Trip2[j] < L) i++; else if (Trip1[i] + Trip2[j] > L) j--; else { printf("possible\n"); return 0; } } } } printf("impossible\n"); return 0; }