• <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 - 21, comments - 2, trackbacks - 0, articles - 0

            HDU 1160 ZOJ 1108 FatMouse's Speed

            Posted on 2011-10-03 03:24 acpeng 閱讀(584) 評論(0)  編輯 收藏 引用 所屬分類: ACM程序
            題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1160
            Problem Description
            FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
             
            Input
            Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
            The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
            Two mice may have the same weight, the same speed, or even the same weight and speed.
            Output
            Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that

            W[m[1]] < W[m[2]] < ... < W[m[n]]

            and

            S[m[1]] > S[m[2]] > ... > S[m[n]]

            In order for the answer to be correct, n should be as large as possible.
            All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
             
            Sample Input
            6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900




            Sample Output
            4 4 5 9 7
            解題思路:
            首先根據weight的數值由小到大排序,然后再以speed為標準,求最長下降子序列,思路還是DP,但是要標記子序列的下標
            麻煩多了,我的做法:
            定義MaxIncludeEnd數組,令MaxIncludeEnd[i]表示以a[i]結尾的最長下降子序列的長度,那么
            MaxIncludeEnd[i]=max{ MaxIncludeEnd[i] , a[j]>a[i] ? (MaxIncludeEnd[j]+1) :-1; }
            其中j=0:i-1;MaxIncludeEnd[i]的初始值為1,每一個i結束后用max和MaxIncludeEnd[i]比較,更新max和下標max_flg。
            因為要標記下標,在計算MaxIncludeEnd[i]后,用flg[i]表示以a[i]結尾的最長下降子序列的前一個元素的下標,這樣計算完
            MaxIncludeEnd[n]并更新完max和max_flg以后,循環遞推一次就可以得到所有的元素下標,即flg[max_flg],flg[ flg[max_flg] ],……
            當然這里的下標是逆向的,要設置個新的數組來將其逆轉。
            ps:如果從后往前計算最長上升子序列,那就不必如此麻煩,減少空間。
            code



            色欲综合久久躁天天躁| 亚洲综合伊人久久大杳蕉| 国产一久久香蕉国产线看观看| 精品久久人妻av中文字幕| 国产成人无码精品久久久久免费 | 久久99国产精品尤物| 国产成人久久精品二区三区| 久久99久久99精品免视看动漫 | 久久久久国产精品熟女影院| 久久99热这里只有精品国产 | 一级A毛片免费观看久久精品| 久久久久亚洲AV无码麻豆| 久久久久亚洲AV成人网人人网站| 亚洲日本va中文字幕久久| 久久综合九色综合久99| 国产精品九九九久久九九| 久久天天婷婷五月俺也去| 国产成人香蕉久久久久| 国产精品久久久久久吹潮| 精品久久久无码人妻中文字幕| 久久久久国产一区二区三区| 青青草原综合久久| 99久久精品日本一区二区免费 | 国产精品99精品久久免费| 久久综合久久美利坚合众国| 久久亚洲国产精品五月天婷| 久久综合久久综合九色| 99久久国产热无码精品免费| 久久夜色精品国产欧美乱| 伊人久久大香线蕉AV色婷婷色| 亚洲精品美女久久久久99小说| 色偷偷91久久综合噜噜噜噜 | 99久久国产热无码精品免费| 无码人妻精品一区二区三区久久 | 久久激情五月丁香伊人| 国产精品美女久久久免费| 99久久夜色精品国产网站| 91久久国产视频| 午夜视频久久久久一区 | 日本久久中文字幕| 国产精品99久久久久久宅男小说|