• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2006年2月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627281234
            567891011

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216441
            • 排名 - 117

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            Hie with the Pie
            Time Limit:2000MS  Memory Limit:65536K
            Total Submit:501 Accepted:183

            Description

            The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.

             

            Input

            Input will consist of multiple test cases. The first line will contain a single integer n indicating the number of orders to deliver, where 1 ≤ n ≤ 10. After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the n locations (numbers 1 to n). The jth value on the ith line indicates the time to go directly from location i to location j without visiting any other locations along the way. Note that there may be quicker ways to go from i to j via other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to go directly from location j to i. An input value of n = 0 will terminate input.

             

            Output

            For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.

             

            Sample Input

            3
            0 1 10 10
            1 0 1 2
            10 1 0 10
            10 2 10 0
            0

             

            Sample Output

            8

             

            Source
            East Central North America 2006

            #include <cstdio>
            #include 
            <memory>

            const int INF = 0x7fffffff;

            int n, d[12][2100];
            int g[12][12];

            void floyd() {
                
            int i, j, k;
                
            for (k=0; k<=n; k++) {
                    
            for (i=0; i<=n; i++) {
                        
            for (j=0; j<=n; j++) {
                            
            if (g[i][k] != -1 && g[k][j] != -1 && (g[i][j] == -1 || g[i][k]+g[k][j] < g[i][j])) {
                                g[i][j] 
            = g[i][k] + g[k][j];
                            }
                        }
                    }
                }
            }

            void solve() {
                
            int i, j, k, bit, t, tmp, one[15], tmpb, ans = INF;
                memset(d, 
            -1, sizeof(d));
                memset(g, 
            -1, sizeof(g));
                
            for (i=0; i<=n; i++) {
                    
            for (j=0; j<=n; j++) {
                        scanf(
            "%d"&g[i][j]);
                    }
                }
                floyd();
                d[
            0][1= 0;
                
            for (i=1; i<=n; i++) {
                    
            for (j=0; j<1<<(n+1); j++) {
                        bit 
            = j; tmp = 0;
                        
            for (k=1; k<=n; k++) {
                            
            if (bit&(1<<k) && bit&1) {
                                one[tmp
            ++= k;
                            }
                        }
                        
            if (tmp != i) continue;
                        
            for (k=0; k<tmp; k++) {
                            tmpb 
            = bit^(1<<one[k]);
                            
            if (d[0][tmpb] != -1 && g[0][one[k]] != -1) {
                                
            if (d[one[k]][bit] == -1 || d[one[k]][bit] > g[0][one[k]] + d[0][tmpb]) {
                                    d[one[k]][bit] 
            = g[0][one[k]] + d[0][tmpb];
                                }
                            }
                            
            for (t=0; t<tmp; t++) {
                                
            if (t == k) continue;
                                
            if (d[one[t]][tmpb] != -1 && g[one[t]][one[k]] != -1) {
                                    
            if (d[one[k]][bit] == -1 || d[one[k]][bit] > g[one[t]][one[k]] + d[one[t]][tmpb]) {
                                        d[one[k]][bit] 
            = g[one[t]][one[k]] + d[one[t]][tmpb];
                                    }
                                }
                            }
                        }
                    }
                }
                
            for (i=0; i<=n; i++) {
                    
            if (d[i][(1<<n+1)-1] != -1 && g[i][0] != -1 && ans > d[i][(1<<n+1)-1]+g[i][0]) ans = d[i][(1<<n+1)-1]+g[i][0];
                }
                printf(
            "%d\n", ans);
            }

            int main() {
                
            while (scanf("%d"&n) != EOF) {
                    
            if (n == 0) break;
                    solve();
                }
                return 
            0;
            }


            posted on 2007-08-03 22:57 閱讀(1269) 評(píng)論(0)  編輯 收藏 引用 所屬分類: ACM題目
            色狠狠久久AV五月综合| 久久精品成人免费观看97| 97久久天天综合色天天综合色hd | 国产精品久久精品| 国产激情久久久久影院老熟女免费 | 久久国产欧美日韩精品免费| 亚洲欧美精品一区久久中文字幕| 蜜桃麻豆WWW久久囤产精品| 99久久精品日本一区二区免费| 国内精品久久久久久麻豆| 久久久久国产精品人妻| 国产精品美女久久久网AV| 一本色道久久88—综合亚洲精品| 婷婷综合久久中文字幕| 一本色道久久综合亚洲精品| 精品免费久久久久国产一区| 久久久久亚洲精品无码蜜桃| 色婷婷久久综合中文久久一本| 69久久夜色精品国产69| 亚洲精品无码久久久久去q| 久久久青草青青国产亚洲免观| 久久久久人妻一区精品性色av| 久久精品综合网| 久久久精品久久久久特色影视 | 少妇被又大又粗又爽毛片久久黑人| 国产精品久久久久久福利69堂| 亚洲国产精品无码久久一区二区 | 中文字幕亚洲综合久久2| 久久婷婷五月综合色奶水99啪| 国产精品久久久久蜜芽| 久久亚洲AV无码西西人体| 久久99精品九九九久久婷婷| 99热精品久久只有精品| 久久亚洲高清观看| A狠狠久久蜜臀婷色中文网| 久久99精品久久久久子伦| 久久久久99精品成人片欧美| 久久国产乱子伦免费精品| 精品久久久久中文字幕日本| 日产精品99久久久久久| 国产精品禁18久久久夂久|