• <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

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

            #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

            久久久久久久久久免免费精品| 久久久久av无码免费网| 国产69精品久久久久99| 国产精品VIDEOSSEX久久发布| 久久综合五月丁香久久激情| 久久久久久国产精品无码下载 | 久久久久黑人强伦姧人妻| 久久伊人影视| 久久成人国产精品二三区| 99久久综合国产精品免费| 91精品无码久久久久久五月天| 2021国内精品久久久久久影院| 久久国产精品99精品国产987| 久久精品中文字幕一区 | 国产香蕉久久精品综合网| 久久w5ww成w人免费| 久久精品国产亚洲av麻豆蜜芽| 国产AⅤ精品一区二区三区久久| 久久久久亚洲AV成人片| 久久人人爽人人爽人人av东京热| 情人伊人久久综合亚洲| 国产亚洲精久久久久久无码| 伊人久久无码精品中文字幕| 精品久久久久久久久久久久久久久| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 久久久久人妻一区精品色 | 久久久久久一区国产精品| 国产亚洲美女精品久久久久狼| 人妻无码αv中文字幕久久琪琪布| 久久久一本精品99久久精品88| 亚洲午夜无码AV毛片久久| 久久亚洲高清综合| 久久男人AV资源网站| 久久久国产精品| 亚洲国产成人精品无码久久久久久综合| 国产精品无码久久久久久| 久久精品aⅴ无码中文字字幕不卡| 怡红院日本一道日本久久 | 精品久久久久久无码中文野结衣| 99久久99久久精品国产片果冻| 国产99久久九九精品无码|