A graph made of n vertices that requires the weight of one of the sum of the least squares of a weight that goes through all points once and then returns to 0 points from Vertex 0
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <climits> #include <cstring> #include <cmath> #include <map> #include <set># Define INF 100000000using namespace std;struct node {int end;int state;}; int N,m;int ma[100][100];int Dp[100][1<<16];int main () {while (CIN >> n >> m) {for (int i = 0;i < m;i++) { int x,y,w;cin >> x >> y >> w;ma[x][y] = w;ma[y][x] = w;//If there is a map just change it here}queue<node> Que;node S;s.end = 0;s.state = 1;dp[s.end][s.state] = 0;que.push (s), while (!que.empty ()) {s = Que.front (), Que.pop (); for (int i = 0;i < N;i + +) {if (Ma[s.end][i]) {if (! ( s.state& (1 << (i))) {//This point has not traversed dp[i][s.state^ (1 << (i))] = Dp[s.end][s.state] + ma[s.end][i];que.push (node{i,s.state^ (1<< (i)});}}} int ans = inf;for (int i = 1;i < n;i++) {if (ma[i][0] && dp[i][(1<<n)-1]) {ans = min (ans,ma[i][0] + dp[i][(1 <<n)-1]);}} cout << ans << Endl;} return 0;}
Minimum Hamilton loop problem state compression DP