• <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

            watashi's mm is so pretty as well as clever. When she has to move to YQ from ZJG, she turns to watashi for help to move her baggages to the baggage office from her dormitory.

            Now watashi has initially total strength s. Because there are so many baggages, watashi may be unable to move all baggages to the baggage office. So, watashi decides to make a perfect plan to reduce the loss.

            Every baggage has three property values v, a, b, that is

            • v: the value of this baggage
            • a: if watashi wants to move this baggage, the must have no less than a strength left. And if he moves this baggage to baggage office, he will loss a strength.
            • b: after watashi moves this baggage and walks back to dormitory, he can recover b strength.

            Now watashi is thinking how can he reduce the least loss, that is to make the total value of baggages in the baggage office largest. Can you help him?

            Input

            There are multiple cases, the first line contains an integer T, representing the number of test cases.

            The first line of each case is two integers, s and n. 10 <= s <= 1000 is the initial strength. 1 <= n <= 100 is the number of baggages.

            The next n lines represents the baggages, each line has three integers 0 <= v, a, b <= 1000 and a > b.

            Output

            An integer V for each case representing the total value baggage that watashi can move to baggage office.

            Sample Input

            1
            9 3
            12 3 1
            13 3 1
            14 7 2
            

            Sample Output

            27
            我暈的咧。。。。
            周六下午的時候根本沒看著題 ,沒想到就是到水題。。。。
            不過還是沒有一次AC。。。。有點不爽,在此膜拜xiaoz大牛,教我們許多DP
            Orz。。。。
            本題為經(jīng)典背包問題O(s*n)時間度算法O(s)空間度。
            核心程序如下
            
             1for(i=0;i<n;i++)
             2        {
             3            for(j=st;j>=0;j--)
             4                if(maxb[j]!=MAX&&j+b[i].a<=st)
             5                {
             6                    int t=j+b[i].a-b[i].b;
             7                    if(maxb[t]!=MAX)maxb[t]=maxb[t]>maxb[j]+b[i].v?maxb[t]:maxb[j]+b[i].v;
             8                    else maxb[t]=maxb[j]+b[i].v;
             9                    if(sum<maxb[t])sum=maxb[t];
            10                }
                
            11        }

            運行結(jié)果:
            2008-12-28 23:51:11 C++ 0 180 聖*騎士
            posted on 2008-12-29 00:05 KNIGHT 閱讀(225) 評論(0)  編輯 收藏 引用

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


            <2008年12月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            伊人久久一区二区三区无码| 精品国产一区二区三区久久久狼| 亚洲欧美成人久久综合中文网 | 久久午夜羞羞影院免费观看| 蜜桃麻豆www久久| 久久久久久国产精品美女| 久久国产视频网| 精品伊人久久大线蕉色首页| 波多野结衣久久| 精品综合久久久久久88小说 | 久久久久久久亚洲精品 | 久久九九亚洲精品| 伊人久久大香线蕉综合网站| 久久午夜无码鲁丝片午夜精品| 久久精品国产欧美日韩99热| 中文精品99久久国产| 久久久亚洲欧洲日产国码是AV| 性欧美大战久久久久久久久| 精品国产乱码久久久久久1区2区| 久久久精品人妻一区二区三区四 | 亚洲国产精品无码久久一线| 色综合久久久久无码专区| 久久国产精品99久久久久久老狼| 亚洲精品视频久久久| 久久久无码人妻精品无码| 一本久久a久久精品综合夜夜| 色诱久久久久综合网ywww| 久久综合狠狠综合久久激情 | 久久久久久亚洲精品影院| 色综合久久久久网| 999久久久免费精品国产| 亚洲国产另类久久久精品| 91超碰碰碰碰久久久久久综合| 亚洲人成伊人成综合网久久久| 狠狠色丁香久久综合婷婷| 四虎影视久久久免费观看| 99久久精品免费看国产免费| 久久伊人影视| 久久97久久97精品免视看秋霞| 麻豆AV一区二区三区久久| 亚洲欧美日韩久久精品|