• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Jogging Trails
            Time Limit: 1000MS
            Memory Limit: 65536K
            Total Submissions: 1710
            Accepted: 672

            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 5 1 2 3 2 3 4 3 4 5 1 4 10 1 3 12 0 

            Sample Output

            41 

            Source

            Waterloo local 2002.07.01

            今天在毛哥的幫助下加深了對此題的理解,題目要求的其實是構造一個歐拉回路,那么:每次加邊,改變兩個奇數點的奇偶性,直到全為偶

            #include<cstdio>
            #include
            <cstring>
            #include
            <iostream>
            using namespace std;
            const int MAXN = 30;
            const int inf = 999999999;
            int dp[1<<15];
            int deg[MAXN],e[MAXN][MAXN];
            void floyd(int n){
                
            for(int k=0;k<n;k++)
                    
            for(int i=0;i<n;i++)
                        
            for(int j=0;j<n;j++)
                            e[i][j]
            =min(e[i][j],e[i][k]+e[k][j]);
            }
            int dfs(int s,int n){
                
            if(!s) return 0;
                
            if(dp[s]>0return dp[s];
                dp[s]
            =inf;
                
            for(int i=0;i<n;i++)
                    
            if(s|(1<<i))
                        
            for(int j=i+1;j<n;j++)
                            
            if(s|(1<<j)){
                                
            int tmp=dfs(s^(1<<i)^(1<<j),n)+e[i][j];
                                
            if(dp[s]>tmp) dp[s]=tmp;
                            }
                
            return dp[s];
            }
            int main(){
                
            int n,m,ans,s,u,v,w;
                
            while(~scanf("%d%d",&n,&m) && n){
                    
            for(int i=0;i<n;i++)
                        
            for(int j=0;j<n;j++)
                            e[i][j]
            =inf;
                    
            for(int i=0;i<n;i++) deg[i]=0;
                    ans
            =0;
                    
            while(m--){
                        scanf(
            "%d%d%d",&u,&v,&w);
                        u
            --;v--;
                        
            if(e[u][v]>w) e[u][v]=e[v][u]=w;
                        ans
            +=w;deg[u]++;deg[v]++;
                    }
                    s
            =0;
                    
            for(int i=0;i<n;i++if(deg[i]%2) s|=(1<<i);
                    memset(dp,
            -1,sizeof(dp));
                    ans
            +=dfs(s,n);
                    printf(
            "%d\n",ans);
                }
                
            return 0;
            }

            posts - 3, comments - 1, trackbacks - 0, articles - 16

            Copyright © lenohoo

            一级做a爰片久久毛片人呢| 久久久久久精品成人免费图片| 亚洲成色WWW久久网站| 久久99精品久久久久久久不卡 | 免费久久人人爽人人爽av| 久久久久免费精品国产| 久久99热只有频精品8| 久久久久久极精品久久久| 亚洲国产精品无码久久久蜜芽| 99久久国产综合精品麻豆| 亚洲一级Av无码毛片久久精品| 亚洲第一极品精品无码久久| 国产伊人久久| 狠狠色婷婷久久一区二区三区| 久久激情五月丁香伊人| 97精品久久天干天天天按摩| 久久亚洲国产成人精品无码区| 精品国产一区二区三区久久| 青青草原综合久久大伊人| 一级做a爰片久久毛片人呢| 久久国产精品无码一区二区三区| 久久精品无码专区免费| 91久久精品91久久性色| 午夜不卡久久精品无码免费| 久久中文字幕视频、最近更新 | 欧美激情精品久久久久久久九九九 | 蜜桃麻豆WWW久久囤产精品| 久久精品嫩草影院| 久久天天躁狠狠躁夜夜avapp| 一本色道久久综合狠狠躁篇 | 国产成人综合久久精品红| 精品久久人人妻人人做精品 | av色综合久久天堂av色综合在 | 久久精品国产亚洲av麻豆色欲| 少妇无套内谢久久久久| 日韩欧美亚洲国产精品字幕久久久| 99久久国产亚洲高清观看2024 | 中文字幕日本人妻久久久免费| 欧美日韩精品久久久久| 久久久国产99久久国产一| 久久久久久久精品成人热色戒|