hdu_2224_The shortest path(dp)
来源:互联网 发布:爱信诺金税盘开票软件 编辑:程序博客网 时间:2024/05/20 20:55
题目连接: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=210;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,1,n)dp[i][i-1]=inf;dp[1][1]=0,dp[2][1]=dis(2,1);FFC(i,3,n)FFC(j,1,i-2)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));return dp[n][n-1]+dis(n,n-1);}int main(){int n;while(~scanf("%d",&n)){FFC(i,1,n)scanf("%lf%lf",&g[i].x,&g[i].y);printf("%.2lf\n",fuck(n));}return 0;}
0 0
- hdu_2224_The shortest path(dp)
- The shortest path-dp+tsp
- HDU 2224The shortest path(dp)
- Shortest Path
- Shortest Path
- Shortest Path
- hdu 224 The shortest path(线性DP)
- 【最短路->DP】SPOJ(ACPC13)[Increasing Shortest Path]题解
- hdoj 3631 Shortest Path
- hdu 3631 Shortest Path
- HDU3631 Shortest Path
- hdoj 3631 Shortest Path
- hdu 3631 Shortest Path
- hdu 3631 Shortest Path
- Hdu 3631 Shortest Path
- HDU3631:Shortest Path(Floyd)
- Shortest Path Faster Algorithm
- Dijkstra Shortest Path
- Android Studio 常用快捷键
- SpringMVC+Mybatis+Oracle(实例)
- ZOJ 2412 Farm Irrigation
- Add Two Numbers
- mysql开启慢查询日志及查询
- hdu_2224_The shortest path(dp)
- http://www.doc88.com/p-7374285513754.html
- 【题解】PAT.团体程序设计天梯赛.L3-004.肿瘤诊断
- bat 命令行
- projectne10向ZedBoard移植
- 中心极限定理及其应用
- 展开与收起效果
- struts2 文件上传
- sql基础常用函数总结