• <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
            我暈的咧。。。。
            周六下午的時(shí)候根本沒看著題 ,沒想到就是到水題。。。。
            不過還是沒有一次AC。。。。有點(diǎn)不爽,在此膜拜xiaoz大牛,教我們?cè)S多DP
            Orz。。。。
            本題為經(jīng)典背包問題O(s*n)時(shí)間度算法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        }

            運(yùn)行結(jié)果:
            2008-12-28 23:51:11 C++ 0 180 聖*騎士
            posted on 2008-12-29 00:05 KNIGHT 閱讀(221) 評(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)論排行榜

            久久亚洲国产成人精品性色| 精品久久久久久国产三级| 无码国内精品久久人妻麻豆按摩| 精品免费tv久久久久久久| 国内精品伊人久久久久| 2021少妇久久久久久久久久| 人妻无码αv中文字幕久久| 色偷偷久久一区二区三区| 77777亚洲午夜久久多喷| 国内精品久久久久影院薰衣草 | 少妇久久久久久被弄到高潮| 久久青青草原综合伊人| 久久国产精品无码网站| 伊人久久成人成综合网222| 久久这里有精品| 无码人妻久久一区二区三区免费丨| 色8久久人人97超碰香蕉987| 国产精品久久亚洲不卡动漫| 成人a毛片久久免费播放| 人妻精品久久久久中文字幕| 亚洲国产成人精品无码久久久久久综合 | 欧美粉嫩小泬久久久久久久 | 久久国产精品99国产精| 久久99国产精品二区不卡| 久久久无码精品亚洲日韩软件| 久久99精品久久久大学生| 久久国产精品99精品国产987| 久久国产免费| 中文字幕一区二区三区久久网站 | 精品无码人妻久久久久久| 少妇无套内谢久久久久| 久久国产精品成人免费| 大香伊人久久精品一区二区| 99久久免费只有精品国产| 久久精品国产亚洲AV影院| 国产精品嫩草影院久久| 久久精品人人做人人妻人人玩| 一本大道久久香蕉成人网| 久久久久久亚洲精品影院| 久久久久亚洲AV无码专区首JN | 久久精品一区二区影院 |