• <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。。。。
            本題為經典背包問題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        }

            運行結果:
            2008-12-28 23:51:11 C++ 0 180 聖*騎士
            posted on 2008-12-29 00:05 KNIGHT 閱讀(234) 評論(0)  編輯 收藏 引用
            <2009年3月>
            22232425262728
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久一本毛久久久| 99久久这里只精品国产免费| 精品蜜臀久久久久99网站| 2022年国产精品久久久久| 亚洲成人精品久久| 亚洲精品WWW久久久久久| 久久九九精品99国产精品| 国产成人无码精品久久久免费 | 久久久久国产一级毛片高清版| 国产毛片久久久久久国产毛片| 亚洲熟妇无码另类久久久| 99久久婷婷国产综合精品草原| 久久这里的只有是精品23| 国内精品久久久久影院免费| 精品久久久无码21p发布| 久久人搡人人玩人妻精品首页| 久久久久久久久久久久中文字幕| 久久精品国产精品亚洲艾草网美妙 | 国产韩国精品一区二区三区久久| 久久影院午夜理论片无码| 国产精品久久久天天影视| 东方aⅴ免费观看久久av | 久久99热这里只有精品国产| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久亚洲av无码精品浪潮| 99热热久久这里只有精品68| 99久久婷婷免费国产综合精品| 亚洲AV无码一区东京热久久| 伊人久久综合无码成人网| 久久天天躁狠狠躁夜夜不卡| 国产女人aaa级久久久级| 国产AⅤ精品一区二区三区久久| 亚洲国产精品久久久久网站| 成人久久久观看免费毛片| 99久久99久久久精品齐齐| 久久久久久久久无码精品亚洲日韩| 久久无码人妻一区二区三区| 99久久精品日本一区二区免费| 精品国产一区二区三区久久久狼| 久久国产精品一国产精品金尊| 人妻精品久久无码区|