HDU 2224 The shortest path 双调旅行商问题
来源:互联网 发布:阿里云 注册域名送邮箱 编辑:程序博客网 时间:2024/05/16 05:08
题目来源:HDU 2224 The shortest path
题意:求从1到n 然后在从n到1的最短路 去的时候经过的点的顺序必须从小到大 来的时候经过的点的顺序必须从大到小 并且每个点只能经过一次(1和n不算) 输出最短路的长度
思路:经典题 参考了大牛http://www.cppblog.com/doer-xee/archive/2009/11/30/102296.html
#include <cstdio>#include <cstring>#include <cmath>using namespace std;const int maxn = 210;double dp[maxn][maxn];double d[maxn][maxn];struct point{ double x, y;}a[maxn];double dis(int i, int j){ return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));}int main(){ int n; while(scanf("%d", &n) != EOF) { for(int i = 1; i <= n; i++) scanf("%lf %lf", &a[i].x, &a[i].y); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { d[i][j] = dis(i, j); } } dp[1][2] = d[1][2]; for(int i = 3; i <= n; i++) { for(int j = 1; j < i-1; j++) dp[j][i] = dp[j][i-1] + d[i-1][i]; dp[i-1][i] = 999999999.0; for(int j = 1; j < i-1; j++) { double sum = dp[j][i-1] + d[j][i]; if(dp[i-1][i] > sum) dp[i-1][i] = sum; } } dp[n][n] = dp[n-1][n] + d[n-1][n]; printf("%.2f\n", dp[n][n]); } return 0;}
0 0
- HDU 2224 The shortest path 双调旅行商问题
- 双调欧几里德旅行商问题--hdu 2224 The shortest path --- POJ 2677Tour
- HDU 2224 The shortest path(双调欧几里得旅行商问题)
- HDU - 2224 The shortest path (双调欧几里德旅行商问题)
- hdu 2224 The shortest path 双调欧几里得旅行商问题(动态规划)
- hdu 2224 The shortest path(双调欧几里得旅行商问题)
- hdu 2224 The shortest path 单向旅行商问题
- HDU 2224 The shortest path_TSP旅行商问题_DP
- hduThe shortest path(双调欧几里得旅行商问题)
- HDU2224The shortest path(双调旅行商问题)经典
- hdu2224The shortest path(双调旅行商问题)
- HDU 2224 The shortest path
- hdu 2224 The shortest path
- HDU 2224 The shortest path
- HDU 2224 The shortest path
- HDU-2224-The shortest path
- hdu2224The shortest path 经典问题之 旅行商问题
- hdu-2224-The shortest path-双调TSP
- Flash Socket 和 Erlang Socket 通信的注意事项
- POJ 2251
- C语言中的左移右移
- 深入浅出TCP之半关闭与CLOSE_WAIT
- RGB转换到HSV颜色空间
- HDU 2224 The shortest path 双调旅行商问题
- Kivy A to Z -- Kivy模块的加载
- 笔记整理----python
- windows游戏编程<十一>封装窗口类
- C++和JAVA的区别 -- 给初学者看
- Proxy(代理模式)
- java命令模式
- 强制断电引起的vmware无法启动的问题解决办法
- 线段树求逆序数hdu1394