题意:

给n个点的坐标,求形成的最短的闭合回路。

分析:

经典问题,dp[i][j]表示有1-i点再由j回到1点的最短距离,i点有两种情况,在去的路径上

dp[i][j]=min(dp[i][j],dp[i-1][j]+dis[i][i-1]);在回的路径上

dp[i][i-1]=min(dp[i][i-1],dp[i-1][j]+dis[

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 1010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[N][N],dis[N][N],x[N],y[N];
int n;
void solve(){
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
dp[i][j]=INF;
dp[][]=;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
{
dp[i][j]=min(dp[i][j],dp[i-][j]+dis[i][i-]);
dp[i][i-]=min(dp[i][i-],dp[i-][j]+dis[j][i]);
}
printf("%.2lf\n",dp[n][n-]+dis[n][n-]);
}
int main()
{
while(~scanf("%d",&n)){
for(int i=;i<=n;++i){
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=;i<=n;++i)
for(int j=i+;j<=n;++j){
dis[i][j]=dis[j][i]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
solve();
}
return ;
}

j][i]); dp[n][n-1]+dis[n][n-1]即为答案

Tour的更多相关文章

  1. POJ 1637 Sightseeing tour

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9276   Accepted: 3924 ...

  2. Euler Tour Tree与dynamic connectivity

    Euler Tour Tree最大的优点就是可以方便的维护子树信息,这点LCT是做不到的.为什么要维护子树信息呢..?我们可以用来做fully dynamic connectivity(online) ...

  3. POJ2677 Tour[DP 状态规定]

    Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4307   Accepted: 1894 Description ...

  4. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

  5. poj1637 Sightseeing tour

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8859   Accepted: 3728 ...

  6. A quick tour of JSON libraries in Scala

    A quick tour of JSON libraries in Scala Update (18.11.2015): added spray-json-shapeless libraryUpdat ...

  7. POJ 1637 Sightseeing tour (混合图欧拉路判定)

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 ...

  8. POJ 1637 Sightseeing tour (混合图欧拉回路)

    Sightseeing tour   Description The city executive board in Lund wants to construct a sightseeing tou ...

  9. POJ2135 Farm Tour

      Farm Tour Time Limit: 2MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description ...

  10. UVa 1347 Tour

    Tour Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Joh ...

随机推荐

  1. dynamic介绍

    Visual C# 2010 引入了一个新类型 dynamic. 该类型是一种静态类型,但类型为 dynamic 的对象会跳过静态类型检查. 大多数情况下,该对象就像具有类型 object 一样. 在 ...

  2. SaaS系列介绍之十三: SaaS系统体系架构

    1 系统体系架构设计 软件开发中系统体系架构决定了一个系统稳定性.健壮性.可扩展性.兼容性和可用性,它是系统的灵魂.体系架构是架构师所关注的核心.良好的体系架构是系统成功的开端,否则,再好的代码与设计 ...

  3. 对cost函数的概率解释

    Likehood函数即似然函数,是概率统计中经常用到的一种函数,其原理网上很容易找到,这里就不讲了.这篇博文主要讲解Likelihood对回归模型的Probabilistic interpretati ...

  4. 英特尔Intel

    公司名称 英特尔(集成电路公司)Intel Corporation(Integrated Electronics Corporation) 英特尔公司是全球最大的半导体芯片制造商,它成立于1968年, ...

  5. 删除元素 不存在 NO 存在 输出余下元素

    #include<stdio.h> #include<stdlib.h> #define N 5 #define NULL 0 #define OK 1 #define ERR ...

  6. shell脚本 -d 是目录文件,那么-e,-f等说明

    -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filename为常规文件,则为真 -L fil ...

  7. 腾讯大讲堂ppt全集

    腾讯大讲堂ppt全集 腾讯大讲堂ppt全集资料下载 腾讯大讲堂ppt1-62资料下载 最新最全的腾讯大讲堂ppt全集 腾讯大讲堂ppt全集资料下载 腾讯大讲堂ppt1-62资料下载地址 http:// ...

  8. Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.

    在部署的时候出现Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server ...

  9. Lists of network protocols

    https://en.wikipedia.org/wiki/Lists_of_network_protocols Protocol stack: List of network protocol st ...

  10. svn: E180001: Unable to open an ra_local session to URL问题解决方案

    在使用Android Studio的SVN导入项目时,出现了: svn: E180001: Unable to open an ra_local session to URLsvn: E180001: ...