• <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) 評(píng)論(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
            解題思路:
            首先根據(jù)weight的數(shù)值由小到大排序,然后再以speed為標(biāo)準(zhǔn),求最長(zhǎng)下降子序列,思路還是DP,但是要標(biāo)記子序列的下標(biāo)
            麻煩多了,我的做法:
            定義MaxIncludeEnd數(shù)組,令MaxIncludeEnd[i]表示以a[i]結(jié)尾的最長(zhǎng)下降子序列的長(zhǎng)度,那么
            MaxIncludeEnd[i]=max{ MaxIncludeEnd[i] , a[j]>a[i] ? (MaxIncludeEnd[j]+1) :-1; }
            其中j=0:i-1;MaxIncludeEnd[i]的初始值為1,每一個(gè)i結(jié)束后用max和MaxIncludeEnd[i]比較,更新max和下標(biāo)max_flg。
            因?yàn)橐獦?biāo)記下標(biāo),在計(jì)算MaxIncludeEnd[i]后,用flg[i]表示以a[i]結(jié)尾的最長(zhǎng)下降子序列的前一個(gè)元素的下標(biāo),這樣計(jì)算完
            MaxIncludeEnd[n]并更新完max和max_flg以后,循環(huán)遞推一次就可以得到所有的元素下標(biāo),即flg[max_flg],flg[ flg[max_flg] ],……
            當(dāng)然這里的下標(biāo)是逆向的,要設(shè)置個(gè)新的數(shù)組來將其逆轉(zhuǎn)。
            ps:如果從后往前計(jì)算最長(zhǎng)上升子序列,那就不必如此麻煩,減少空間。
            code



            久久夜色精品国产亚洲| 狠狠色综合网站久久久久久久| 久久综合视频网站| 色妞色综合久久夜夜| 欧美午夜精品久久久久免费视| 2020久久精品国产免费| 久久精品国产色蜜蜜麻豆 | 国产三级久久久精品麻豆三级 | 日韩欧美亚洲综合久久 | 性做久久久久久久久浪潮| 亚洲va中文字幕无码久久| 久久青草国产手机看片福利盒子| 人妻精品久久久久中文字幕| AV无码久久久久不卡蜜桃| 91久久精品电影| 久久精品国产第一区二区三区 | 99久久国产亚洲高清观看2024| 九九精品久久久久久噜噜| 国内精品伊人久久久久网站| 伊人久久久AV老熟妇色| 精品人妻伦九区久久AAA片69 | 精品免费久久久久久久| 久久伊人五月丁香狠狠色| 青青青国产精品国产精品久久久久 | 亚洲熟妇无码另类久久久| 久久久久国产精品麻豆AR影院 | 久久天天躁狠狠躁夜夜躁2014| 国产高潮国产高潮久久久91| 久久96国产精品久久久| 国产精品无码久久久久久| 精品伊人久久大线蕉色首页| 亚洲国产香蕉人人爽成AV片久久| 国内精品久久久久久久coent | 精品一二三区久久aaa片| 理论片午午伦夜理片久久 | 亚洲另类欧美综合久久图片区| 久久精品成人| 久久综合视频网| 色欲久久久天天天综合网精品| 少妇高潮惨叫久久久久久| 久久精品亚洲日本波多野结衣 |