• <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>
            posts - 74,  comments - 33,  trackbacks - 0
            Islands and Bridges
            Time Limit: 4000MS Memory Limit: 65536K
            Total Submissions: 2930 Accepted: 723

            Description

            Given a map of islands and bridges that connect these islands, a Hamilton path, as we all know, is a path along the bridges such that it visits each island exactly once. On our map, there is also a positive integer value associated with each island. We call a Hamilton path the best triangular Hamilton path if it maximizes the value described below.

            Suppose there are n islands. The value of a Hamilton path C1C2...Cn is calculated as the sum of three parts. Let Vi be the value for the island Ci. As the first part, we sum over all the Vi values for each island in the path. For the second part, for each edge CiCi+1 in the path, we add the product Vi*Vi+1. And for the third part, whenever three consecutive islands CiCi+1Ci+2 in the path forms a triangle in the map, i.e. there is a bridge between Ci and Ci+2, we add the product Vi*Vi+1*Vi+2.

            Most likely but not necessarily, the best triangular Hamilton path you are going to find contains many triangles. It is quite possible that there might be more than one best triangular Hamilton paths; your second task is to find the number of such paths.

            Input

            The input file starts with a number q (q<=20) on the first line, which is the number of test cases. Each test case starts with a line with two integers n and m, which are the number of islands and the number of bridges in the map, respectively. The next line contains n positive integers, the i-th number being the Vi value of island i. Each value is no more than 100. The following m lines are in the form x y, which indicates there is a (two way) bridge between island x and island y. Islands are numbered from 1 to n. You may assume there will be no more than 13 islands.

            Output

            For each test case, output a line with two numbers, separated by a space. The first number is the maximum value of a best triangular Hamilton path; the second number should be the number of different best triangular Hamilton paths. If the test case does not contain a Hamilton path, the output must be `0 0'.

            Note: A path may be written down in the reversed order. We still think it is the same path.

            Sample Input

            2
            3 3
            2 2 2
            1 2
            2 3
            3 1
            4 6
            1 2 3 4
            1 2
            1 3
            1 4
            2 3
            2 4
            3 4
            

            Sample Output

            22 3
            69 1
            以前做本校的1005的時候,其中就用到TSP,當(dāng)然KM也能正確求解,暴搜更是無敵!
            現(xiàn)在這是一道變形的TSP,搞清題目意思就很容易求解,不幸的是在統(tǒng)計路徑的時候,我居然
            腦殘的sum++,而應(yīng)該是sum+=dpways[(1<<n)-1][i][j];因此白白的貢獻了N個WA,
            腦殘人士!請見諒!
            代碼很慢,735ms,不貼了!
            -------------------------------------------------------------------------------------------
            上課去了!??!
            posted on 2009-03-26 09:56 KNIGHT 閱讀(123) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2009年5月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久国产精品嫩草影院| 久久影院午夜理论片无码 | 久久综合九色综合97_久久久 | 久久精品国产亚洲AV忘忧草18| 99久久免费国产精品特黄| 久久精品午夜一区二区福利| 91久久精品国产免费直播| 狠狠色丁香久久婷婷综合_中 | 国产精品久久久久jk制服| 久久996热精品xxxx| 久久久精品人妻一区二区三区四 | 伊人久久亚洲综合影院| 国产Av激情久久无码天堂| 久久久久亚洲AV综合波多野结衣| 亚洲va久久久噜噜噜久久狠狠| 99国内精品久久久久久久| 久久中文骚妇内射| 免费精品国产日韩热久久| 国产高潮久久免费观看| AV色综合久久天堂AV色综合在| 伊人久久无码精品中文字幕| 久久99精品久久久久久水蜜桃| 久久国产乱子伦免费精品| 久久中文字幕人妻熟av女| 日本久久中文字幕| 久久久久久亚洲精品不卡| 狠狠色丁香婷婷综合久久来来去| 国产精品99久久免费观看| 久久久久久久女国产乱让韩| 久久国产AVJUST麻豆| 97视频久久久| 久久久久久久波多野结衣高潮| 欧美日韩成人精品久久久免费看| 精品久久久久久久久久中文字幕| 久久国产精品99久久久久久老狼| 狠狠88综合久久久久综合网| 久久婷婷成人综合色综合| 伊人久久无码中文字幕| 久久国产精品一国产精品金尊| 亚洲第一极品精品无码久久| 色诱久久久久综合网ywww|