poj 2404

Jogging Trails
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1462   Accepted: 552

Description

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

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.

Output

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

Sample Output

41

Source

Waterloo local 2002.07.01
分析:floyd+状态压缩DP
           用floyd求两点间最短路,由欧拉回路可知,度为奇数的点之间互相匹配(即连一条边),选这些边之和最小值加上
          所有边及答案,匹配时可用记忆搜(即状态压缩优化dfs)。。。。
ps:
          由于个人失误搞了许久。。。囧,开始用第一种
          写错了,第二种,倒过来却过了。。。改了许久才发现。。。是变量赋值的问题
程序1:
#include using namespace std; int w[15][15],p[15],add[1<<15],n,m,ans; void dfs(int s) { if(s==(1<
 
程序2:
#include using namespace std; int w[15][15],p[15],add[1<<15],n,m,ans; int dfs(int s) { if(add[s]>-1)return add[s]; add[s]=1<<29; int i,j; for(i=0;itmp)add[s]=tmp; } return add[s]; } void floyd() { for(int k=0;k

你可能感兴趣的:(poj 2404)