题目连接: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. C++编程技巧(长期更新)

    1.数组使用 int* p = new int[5](); // 数组新建并全部初始化为0 等价于: int* p; p = new int[5](); int* q = new int[5];    ...

  2. 找工作---操作系统常考知识点总结【PB】

    1.进程是并发过程中程序的执行过程 2.进程的特征:结构特征.动态性.并发性.独立性.异步性 3.临界区指在每个进程中访问临界资源的那段代码 4,现在操作系统中申请资源的基本单位是进程,在CPU得到执 ...

  3. CSS兼容的一些问题

    DIV+CSS网页布局这是一种趋势,我也开始顺应这股趋势了,不过在使用DIV+CSS网站设计的时候,应该注意css样式兼容不同浏览器问题,特别是对完全使用DIV+CSS设计的网页,就应该更注意IE6 ...

  4. 使用bootstrap建立响应式网页——通栏轮播图(carousel)

    1.bootstrap提供了js插件——轮播图 我们还是照旧,直接拿过来用,需要改的地方再说. 2.修改 小屏幕看小图,大屏图看大图:这个可以利用自定义属性(data-XXX)data-img-lg( ...

  5. POJ 2209 The King#贪心

    (- ̄▽ ̄)-*  水 //水题:潜力^e为正数(e为2时都可以)的儿子都可以去上战场了, //英文要看懂,exponent指数,不超过3的正数 #include<iostream> #i ...

  6. Java IO 节点流 FileInput/OutputStream

    Java IO 节点流 FileInput/OutputStream @author ixenos 节点流之 文件流 文件读写是最常见的I/O操作,通过文件流来连接磁盘文件,读写文件内容 1.文件的读 ...

  7. Computation expressions: Introduction

    本文仅为对原文的翻译,主要是记录以方便以后随时查看.原文地址为http://fsharpforfunandprofit.com/posts/computation-expressions-intro/ ...

  8. nginx在linux下的目录结构

    配置文件目录 putty 下  whereis nginx /etc/nginx

  9. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 3259 Wormholes

    SPFA求负环 模板题 记得每组处理之前clear vector /* *********************************************** Author :Sun Yuef ...

  10. stl 生产全排列 next_permutation

    #include<stdio.h>#include<algorithm>using namespace std;int main(){ int n,p[10]; scanf(& ...