hdu_2224_The shortest path(dp)
题目连接: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)的更多相关文章
- 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 ...
- 74(2B)Shortest Path (hdu 5636) (Floyd)
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDU 5636 Shortest Path(Floyed,枚举)
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tot ...
- [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 ...
- UVAlive 6756 Increasing Shortest Path
We all love short and direct problems, it is easier to write, read and understand the problem statem ...
- hdu-----(2807)The Shortest Path(矩阵+Floyd)
The Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- zoj 2760 How Many Shortest Path 最大流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...
- The Shortest Path in Nya Graph
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
随机推荐
- JS时间日期格式转换
第一种: function ConvertJSONDate(jsondate) { if (jsondate != "" && jsondate ...
- Hadoop-2.6.0安装文档
前段时间在dataguru上报了一个hadoop的培训班,希望能够帮助自己更快的了解.掌握并且熟悉hadoop的开发和原理. 上一期的作业是要自己搭建一个hadoop的环境,并能运行mapreduce ...
- Idea把依赖打入Jar包,Maven项目步骤
1:修改pom.xml安装assembly插件 1:修改pom.xml 安装assembly插件 <plugin> <artifactId>maven-assembly-plu ...
- box2d 计算自由落体下一帧的位置
var dt:Number=1/30; var y0:Number=_body.GetPosition().y; var y:Number=y0+_body.GetLinearVelocity().y ...
- js监听事件 上滑消失下滑出现的效果 触摸与手势事件
https://www.w3cmm.com/javascript/touch.html //触摸与手势事件连接tinyscrollbar //方法1var _this = $('#fabu');var ...
- seajs简记
参考seajs快速入门 一.前端模块化的价值 解决命名冲突 摆脱文件依赖 性能优化 提高可维护性 seajs.use方法调用通过exports暴露接口通过require引入依赖 二.Sea.js 的常 ...
- android 实现透明状态栏
主要使用https://github.com/jgilfelt/SystemBarTint这个开源库 1 ,导入SystemBarTintManager类 2 ,BaseFragmentActivit ...
- ZOJ 2710 Two Pipelines
计算几何+贪心 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm&g ...
- 实验吧Web-Forms
链接: http://www.shiyanbar.com/ctf/1819 题目: F12调试: 果断把showsource域的value值改为1 在框里随便输入内容,回车,显示出了源代码 说明Pin ...
- 关于cocos2dx的C++调用创建项目
我使用的是cocos2dx-2.1.4版本+cygwin,其实主要是为了配合公司项目,所以用了低版本的cocos2dx 假设已经配置环境成功: 按照对应的要求输入包名,项目名,以及TargetId,就 ...