[Link].
APPROXIMATION ALGORITHM-9024-RAMU
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#define MAX_POINTS 100
struct Point {
int x;
int y;
};
double distance(struct Point p1, struct Point p2)
{ return sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y,
2));
void computeDistanceMatrix(struct Point points[], int num_points, double distances[][MAX_POINTS])
{
for (int i = 0; i < num_points; i++)
{ for (int j = 0; j < num_points; j++)
distances[i][j] = distance(points[i], points[j]);
}
double heldKarpTSP(int num_points, double distances[][MAX_POINTS])
{ int num_states = 1 << num_points;
double dp[num_states][MAX_POINTS];
for (int i = 0; i < num_states; i++) {
for (int j = 0; j < num_points; j++) {
dp[i][j] = -1