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

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


            <2009年3月>
            22232425262728
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            精品永久久福利一区二区| 亚洲午夜久久久影院| 色欲久久久天天天综合网| 久久精品国产亚洲AV高清热| 国产精品青草久久久久婷婷 | 亚洲AV无码久久精品成人| 色综合久久综合中文综合网| 久久综合噜噜激激的五月天 | 国产精品成人无码久久久久久| 狠狠色婷婷综合天天久久丁香| 国产亚洲精久久久久久无码AV| 亚洲第一极品精品无码久久| 久久精品a亚洲国产v高清不卡| 国产免费久久精品丫丫| 漂亮人妻被中出中文字幕久久| 伊人久久大香线蕉精品| 亚洲国产精品无码成人片久久| 久久99毛片免费观看不卡| 日日狠狠久久偷偷色综合0| 91视频国产91久久久| 久久天天躁狠狠躁夜夜2020老熟妇| 蜜桃麻豆www久久| 亚洲色大成网站www久久九| 久久久精品午夜免费不卡| 日韩欧美亚洲国产精品字幕久久久 | 人妻丰满AV无码久久不卡| 中文字幕久久精品| 国产精品综合久久第一页| 浪潮AV色综合久久天堂| 狠狠色丁香久久婷婷综合图片| 国产精品热久久毛片| 国产99久久精品一区二区| 中文字幕乱码久久午夜| 亚洲国产综合久久天堂| 久久精品无码免费不卡| 亚洲伊人久久成综合人影院 | .精品久久久麻豆国产精品| 久久99热这里只有精品国产| 久久亚洲春色中文字幕久久久| 一级a性色生活片久久无少妇一级婬片免费放| 国产精品禁18久久久夂久|