/*F[i][j] represents the optimal solution of the point of the past that constitutes I state and the last point reached is J when the last State is (1<<n+1)-1 each point arrives at this back to 0*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 100010//minimum to 1<<16using namespacestd;intn,g[ -][ -],f[maxn][ -],ans=0x3f3f3f3f;intMain () {scanf ("%d",&N); for(intI=0; i<=n;i++) for(intj=0; j<=n;j++) scanf ("%d",&G[i][j]); for(intk=0; k<=n;k++) for(intI=0; i<=n;i++) for(intj=0; j<=n;j++) G[i][j]=min (g[i][k]+G[k][j],g[i][j]); Memset (F,127/3,sizeof(f)); f[1][0]=0;//Initialize for(intI=1; I<= (1<<n+1)-1; i++)//enumerate the state of the traversed point composition for(intj=0; j<=n;j++)//enumerates the last point reached if((1<<J) &i)//J walked. { for(intk=0; k<=n;k++) F[i| (1<<k)][k]=min (f[i| (1<<K)][k],f[i][j]+G[j][k]); } for(intI=1; i<=n;i++) ans=min (ans,g[i][0]+f[(1<<n+1)-1][i]); printf ("%d\n", ans); return 0;}
Codevs 2800 off-sell