# HDU 4765 Tsp 2013长春网络赛G题 DP

1043人阅读 评论(0)

- Mo can't go to location j+ from i+ if j > i;
- Mo can't go to location j- from i- if j < i;
- If Mo has visited location i-, location j+ will be removed from the world and cannot be visited any more if j < i.

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;
const int maxn=110;
int d[maxn*2][2];
double dp[maxn][maxn][maxn],dist[maxn*2][maxn*2];
int tag[maxn][maxn][maxn][2];
int n;
double dis(int i,int j)
{
return sqrt((double)(d[i][0]-d[j][0])*(d[i][0]-d[j][0])+(d[i][1]-d[j][1])*(d[i][1]-d[j][1]));
}
void pre()
{
for (int i=1;i<=n;i++)
scanf("%d%d%d%d",&d[i][0],&d[i][1],&d[i+n][0],&d[i+n][1]);

for (int i=1;i<=2*n;i++)
for (int j=1;j<=2*n;j++)
dist[i][j]=dis(i,j);
}
void find(int i,int head,int tail)
{
double front=-1,behind=-1;

{
{
{
}
}
}
else
{
front=dist[i][i+n];
}
if (i<tail)//到i-以后还要装；//从i-到tail-；
{
for (int k=i+1;k<=tail;k++)//下一个走的点是k;
{
if (tag[k][i+1][tail][0]==-1)
find(k,i+1,tail);
if (behind==-1||behind>dist[i+n][k]+dp[k][i+1][tail])
{
behind=dist[i+n][k]+dp[k][i+1][tail];
}
}
}
else
{
behind=0;
}
return;
}
void dfs(int i,int head,int tail)
{
printf("%d+ ",i);
{
}
if (i<n)
printf("%d- ",i);
else printf("%d-\n",i);
if (i<tail)
{
}
}
int main()
{
//freopen("in.txt","r",stdin);
while (~scanf("%d",&n))
{
pre();
memset(tag,-1,sizeof(tag));
int star;
int minn=-1;
for (int i=1;i<=n;i++)
{
find(i,1,n);
if (minn==-1||minn>dp[i][1][n])
{
minn=dp[i][1][n];
star=i;
}
}
dfs(star,1,n);
}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：12002次
• 积分：319
• 等级：
• 排名：千里之外
• 原创：21篇
• 转载：0篇
• 译文：0篇
• 评论：2条
文章分类
阅读排行
最新评论