题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2224

题意:双调欧几里德旅行商经典问题,找一条最短回路使得该路经过所有的点

题解: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(i,j));,注意这里题目的数据给的是从左往右的,所以不需要排序

 #include<cstdio>
#include<cmath>
#define FFC(i,a,b) for(int i=a;i<=b;i++)
const int maxn=;
double dp[maxn][maxn],inf=1e9;
struct node{double x,y;}g[maxn];
double Min(double a,double b){return a>b?b:a;}
double dis(int i,int j){return sqrt((g[i].x-g[j].x)*(g[i].x-g[j].x)+(g[i].y-g[j].y)*(g[i].y-g[j].y));}
double fuck(int n){
FFC(i,,n)dp[i][i-]=inf;
dp[][]=,dp[][]=dis(,);
FFC(i,,n)FFC(j,,i-)
dp[i][j]=dp[i-][j]+dis(i,i-),dp[i][i-]=Min(dp[i][i-],dp[i-][j]+dis(i,j));
return dp[n][n-]+dis(n,n-);
}
int main(){
int n;
while(~scanf("%d",&n)){
FFC(i,,n)scanf("%lf%lf",&g[i].x,&g[i].y);
printf("%.2lf\n",fuck(n));
}
return ;
}

hdu_2224_The shortest path(dp)的更多相关文章

  1. leetcode_1293. Shortest Path in a Grid with Obstacles Elimination_[dp动态规划]

    题目链接 Given a m * n grid, where each cell is either 0 (empty) or 1 (obstacle). In one step, you can m ...

  2. 74(2B)Shortest Path (hdu 5636) (Floyd)

    Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. HDU 5636 Shortest Path(Floyed,枚举)

    Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...

  4. [LeetCode] 847. Shortest Path Visiting All Nodes 访问所有结点的最短路径

    An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph. graph.lengt ...

  5. UVAlive 6756 Increasing Shortest Path

    We all love short and direct problems, it is easier to write, read and understand the problem statem ...

  6. hdu-----(2807)The Shortest Path(矩阵+Floyd)

    The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. zoj 2760 How Many Shortest Path 最大流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...

  8. The Shortest Path in Nya Graph

    Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...

  9. hdu 3631 Shortest Path(Floyd)

    题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...

随机推荐

  1. 扯扯maven的蛋

    同样是放在有道云笔记里,各种散乱加发霉,抽空来整理整理,分几个部分来扯扯maven. 一.Maven是啥求. Maven 为Apache 组织中的开源项目,主要服务于基于Java 平台的项目构建.依赖 ...

  2. Lucene全文检索技术

    Lucene全文检索技术 今日大纲 ●    搜索的概念.搜索引擎原理.倒排索引 ●    全文索引的概念 ●    使用Lucene对索引进行CRUD操作 ●    Lucene常用API详解 ●  ...

  3. 计算机网络课程优秀备考PPT之第一章概述(一)

    为了记录自己从2016.9~2017.1的<计算机网络>助教生涯,也为了及时梳理和整写笔记! 以上,是<计算机网络>课程的第一章概述.

  4. 第七十三节,css盒模型

    css盒模型 学习要点: 1.元素尺寸 2.元素内边距 3.元素外边距 4.处理溢出 本章主要探讨HTML5中CSS盒模型,学习怎样了解元素的外观配置以及文档的整体布局. 一.元素尺寸 CSS盒模型中 ...

  5. bashrc - PS1(提示符配色)

    PS1设置: liBlack="\[\033[0;30m\]"boBlack="\[\033[1;30m\]"liRed="\[\033[0;31m\ ...

  6. Vue - 使用命令行搭建单页面应用

    使用命令行搭建单页面应用 我们来看一下最后完成的效果: 大纲 1. 下载 node, git, npm 2. 使用命令行安装一个项目 一. 下载工具 node , git  的下载大家可以去官网自行下 ...

  7. 二分法经典习题——HDU1969

    #include <iostream>#include <cmath>#include <iomanip>using namespace std; double p ...

  8. asp.net 批量删除

    直接上代码: 1.页面部分 <script type="text/javascript" src="http://code.jquery.com/jquery-1. ...

  9. 自己造容器List

    //自己造容器--List /* 1.iterator 2.头迭代器 3.尾迭代器 4.链表长 5.判空 6.清除 7.取头元素 8.取尾元素 9.头插入 10.尾插入 11.头删除 12.尾删除 1 ...

  10. OpenGL多视口

    #include <gl/glew.h> #include <gl/freeglut.h> #include <iostream> ; ; float rtri = ...