Since the jump need 400, greater than in the fan lane in one lap, so should be as few as possible to jump the fan path, converted into a double travel business problems,
That is, starting from Zone 0 to the largest area, and then back to Zone 0, all intermediate points need to go to one
#include "stdio.h" #include "string.h" #include "math.h" #include "algorithm" using namespace std;struct node{int x, y;} A[1010];int Abs (int a) {if (a<0) return-a; else return A;} BOOL CMP (node A,node b) {if (a.x!=b.x) return a.x<b.x; else return a.y<b.y;} int N;int inf=0x3f3f3f3f;int dis[1010][1010],dp[1010][1010];int cal (int i,int j) {int temp,mark; Temp=0; if (a[i].x!=a[j].x) temp+=abs (a[i].x-a[j].x) *400; Mark=abs (A[I].Y-A[J].Y); if (mark>180) Mark=360-mark; Temp+=mark; return temp;} void DP () {int i,j,temp; DP[0][1]=DIS[0][1]; for (j=2;j<=n;j++) {for (i=0;i<j-1;i++) dp[i][j]=dp[i][j-1]+dis[j][j-1]; for (i=0;i<j-1;i++) {temp=dp[i][j-1]+dis[i][j]; if (Temp<dp[j-1][j]) dp[j-1][j]=temp; }} Dp[n][n]=dp[n-1][n]+dis[n-1][n];} int main () {int i,j,t; scanf ("%d", &t); while (t--) {scanf ("%d", &n); for (I=1; i<=n;i++) scanf ("%d%d", &a[i].x,&a[i].y); a[0].x=a[0].y=0; Sort (a,a+n+1,cmp); for (i=0;i<=n;i++) for (j=0;j<=n;j++) dis[i][j]=cal (I,J); Memset (Dp,inf,sizeof (DP)); DP (); printf ("%d\n", dp[n][n]+10*n); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4824 two-tone travel quotient issue