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 ...
随机推荐
- GitHub上优秀的ThirdParty
仅为个人记录. 1.SwiftyJSON GitHub地址:https://github.com/SwiftyJSON/SwiftyJSON 2.CryptoSwift GitHub地址:https: ...
- linux下卸载和安装mysql数据库的方法
1.1 MySQL下载 下载地址:http://www.mysql.com/downloads/mysql/5.5.html#downloads 版本:5.1.68 平台:linux general ...
- python_批量修改文件名
1.在movies文件夹下面的所有文件前面都加上[可可可可] #coding:utf-8 import os movie_name = os.listdir('./movies') for temp ...
- neutron openvswitch agent实现安全组的方法
关于openstack安全组,采用一问一答的形式记录如下 1. 是加载在计算节点的还是网络节点的? 是加载在计算节点的 2. 是使用iptable规则实现的吗? M版的neutron实现了openvs ...
- Idea1.5使用Maven搭建Apache Spark1.6源码阅读环境
1.插件安装,在Idea界面依次:File->settings->plugins,安装Maven 2.下载Spark1.6.2源码,这个在GitHub上下载,具体流程自己百度,很简单 3. ...
- USACO 1.3 Ski Course Design
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- 《JS权威指南学习总结--开始简介》
本书共分成了四大部分: 1.JS语言核心 2.客户端JS 3.JS核心参考 4.客户端JS核心参考 其中 <JS权威指南学习总结--1.1语法核心> 是:第一部分JS语言核心 各章节重点 ...
- hdu_5877_Weak Pair(离散+DFS+树状数组)
题目链接:hdu_5877_Weak Pair 题意: 给你一棵树,让你找有多少对满足那两个条件的weak pair 题解: 有人用Treap,我不会,然后我用树状数组+离散来替代Treap,用DFS ...
- Tomcat基础
一.Tomcat体系结构 tomcat应该是java程序员最熟悉的servlet容器了,作为一个用java实现的web应用程序服务器,下图是tomcat的体系结构 一个常见的Tomcat配置文件以下x ...
- Leetcode016 3Sum Closest
public class S016 { //借鉴S015的思想,只是稍微有点慢 public int threeSumClosest(int[] nums, int target) { Arrays. ...