uva 10296 - Jogging Trails (中国邮路问题 状压dp)
来源:互联网 发布:剑三捏脸数据正太 编辑:程序博客网 时间:2024/05/19 01:09
Problem B: Jogging Trails
Gord is training for a marathon. Behind his house is a park with a large network of jogging trails connecting water stations. Gord wants to find the shortest jogging route that travels along every trail at least once.Input consists of several test cases. The first line of input for each case contains two positive integers: n <= 15, the number of water stations, and m < 1000, the number of trails. For each trail, there is one subsequent line of input containing three positive integers: the first two, between 1 and n, indicating the water stations at the end points of the trail; the third indicates the length of the trail, in cubits. There may be more than one trail between any two stations; each different trail is given only once in the input; each trail can be travelled in either direction. It is possible to reach any trail from any other trail by visiting a sequence of water stations connected by trails. Gord's route may start at any water station, and must end at the same station. A single line containing 0 follows the last test case.
For each case, there should be one line of output giving the length of Gord's jogging route.
Sample Input
4 51 2 32 3 43 4 51 4 101 3 120
Output for Sample Input
#include<cstdio>#include<map>#include<queue>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<list>#include<set>#include<cmath>using namespace std;const int maxn = 100 + 5;const int INF = 1e9;const double eps = 1e-6;typedef unsigned long long ULL;typedef long long LL;typedef pair<int, int> P;#define fi first#define se secondint n, m;int dis[maxn][maxn];void floyd(){ for(int k = 1;k <= n;k++){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++) dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]); } }}int degree[maxn], dp[1<<20];int solve(int now){ if(now == 0) return 0; if(dp[now] != -1) return dp[now]; int ret = INF; for(int i = 1;i <= n;i++){ if(now&(1<<(i-1))){ for(int j = i+1;j <= n;j++){ if(now&(1<<(j-1))){ ret = min(ret, dis[i][j]+solve(now-(1<<(i-1))-(1<<(j-1)))); } } } } return dp[now] = ret;}int main(){ while(cin >> n){ if(n == 0) break; cin >> m; memset(degree, 0, sizeof degree); for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++) dis[i][j] = INF; dis[i][i] = 0; } int ans = 0; while(m--){ int x, y, c; cin >> x >> y >> c; dis[x][y] = dis[y][x] = min(dis[x][y], c); degree[x]++; degree[y]++; ans += c; } floyd(); int ori = 0; for(int i = 1;i <= n;i++){ ori += ((degree[i]&1)<<(i-1)); } memset(dp, -1, sizeof dp); ans += solve(ori); cout << ans << endl; } return 0;}
- uva 10296 - Jogging Trails (中国邮路问题 状压dp)
- UVA - 10296 Jogging Trails (中国邮路问题)
- [中国邮路问题 欧拉回路 最短路 一般图匹配||状压DP] FZU 1009 Jogging Trails
- POJ 2404 Jogging Trails (中国邮递员问题,状态压缩DP)
- Light OJ 1086 Jogging Trails (Floyd+状压DP)
- POJ-2404 Jogging Trails (中国邮递员)
- poj 2404 Jogging Trails 状压dp
- lightoj1086 - Jogging Trails(状态压缩dp)
- Light oj 1086 - Jogging Trails(状压dp 将图变成欧拉图)
- 1086 - Jogging Trails (欧拉回路+dp)
- 中国邮路问题
- 中国邮路问题 ZOJ1903
- JOJ1871:Jogging Trails
- FZU1009 Jogging Trails
- POJ 2404 Jogging Trails
- lightoj1086 Jogging Trails
- POJ2404:Jogging Trails
- LightOJ - 1086 Jogging Trails(欧拉+状态压缩)
- android获取系统自带浏览器书签
- adb client, adb server, adbd原理浅析
- POJ2185-Milking Grid(KMP,next数组的应用)
- String 的split
- kendo AutoComplete实现多筛选条件
- uva 10296 - Jogging Trails (中国邮路问题 状压dp)
- Java开发桌面程序SWING,设置主窗口位置居中一般使用下面的方法
- BZOJ 1079: [SCOI2008]着色方案
- 如何3分钟算出一家创业公司的估值
- 常见的假冒软玉的玉石
- C++程序设计(7)之自定义数据类型
- 插入排序和希尔排序
- 创业:“天使、VC、PE、IPO”4 时间节奏不能乱
- 配置DID账号