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

            hit1485

            A Good Helper

            My Tags   (Edit)

            Source : HCPC 2004

            Time limit : 1 sec
            Memory limit : 32 M

            Submitted : 476, Accepted : 205

            Abraham and Calford are Moving their things from dormitory A11 to A9,and they have their own carry limit,they can't carry things which is beyond their limit and they will not carry one bag together. They want things to be carried in one time,when they can't deal with so many things, they will hire a good helper to help them, who can only carry one bag of things, regardless of the weight of it. Your task is to tell whether they can carry their bags in one time,or not.

            Input
            There are multiple test cases.
            First line of each test case contains two nonnegative numbers, A and C, (0 < A,C <=1000) representing the limit of Abraham and Calford,then the second line contains an integer N ( 0 < N <= 200 ) ,representing the number of bags,followed by N positive integers,each of them is not more than 100.

            Output
            For each test case
            Output "Yes" if they can carry the bags without the help of the helper in one time.
            Output "Need a helper" if they can only carry the bags with the help of the helper in one time.
            Output "No" if they can't carry the bags in one time.

            Sample Input

            7 7 
            3 5 5 5
            7 7
            3 5 2 5
            7 7
            3 7 8 7
            7 7
            3 7 8 9

            Sample Output

            Need a helper
            Yes
            Need a helper
            No
            額,這個(gè)題有兩個(gè)包,還有一個(gè)good helper,當(dāng)時(shí)不知道怎么寫(xiě),覺(jué)著是dp,然后想出了個(gè)二維的方程,復(fù)雜度奇高

            然后找了下題解才發(fā)現(xiàn)可以這樣做

            只對(duì)第一個(gè)人dp,如果讓第一個(gè)人盡量裝,然后看剩下的第二個(gè)人能不能全部帶走,如果可以則Yes

            不行則看,如果去除重量最大的一個(gè)兩個(gè)人能不能拿走,可以則Need a helper 否則No

            這個(gè)helper可以拿任意重的東西,所以如果可能則可以選擇把最重的物品給他

            我們可以在預(yù)處理的時(shí)候把最終的放到最后面

            f[i][j]表示前i件物品,用j的重量時(shí)候能拿走的最大重量

            然后這樣就是個(gè)簡(jiǎn)單的一維背包了,那么f[n-1][a]則是出去最重一個(gè)物品后能取得的最大值

            根據(jù)背包九講,我們可以優(yōu)化空間到一維,但在枚舉費(fèi)用時(shí)候要倒序

             1 #include<stdio.h>
             2 #include<string.h>
             3 #include<math.h>
             4 int f[1300],a,c;
             5 int n,v[240];
             6 int big,tmp,xi;
             7 int tot;
             8 void init()
             9 {
            10     int i,temp;
            11     scanf("%d",&n);
            12     big=0;
            13     tot=0;
            14     for(i=1;i<=n;i++)
            15     {
            16         scanf("%d",&v[i]);
            17         tot+=v[i];
            18         if (v[i]>big)
            19         {
            20             big=v[i];
            21             xi=i;
            22         }
            23     }
            24     temp=v[xi];v[xi]=v[n];v[n]=temp;
            25 }
            26 int max(int a,int b)
            27 {
            28     if (a>b) return a; else return b;
            29 }
            30 void work()
            31 {
            32     int i,j;
            33     memset(f,0,sizeof(f));
            34     for (i=1;i<=n ;i++ )
            35     {
            36         for (j=a;j>=v[i] ;j-- )
            37         {
            38             tmp=f[a];
            39             f[j]=max(f[j-v[i]]+v[i],f[j]);
            40         }
            41     }
            42     if (f[a]+c>=tot) printf("Yes\n");
            43     else if (tmp+c>=tot-big) printf("Need a helper\n");
            44     else printf("No\n");
            45 }
            46 int main()
            47 {
            48     while (scanf("%d%d",&a,&c)!=EOF)
            49     {
            50         init();
            51         work();
            52     }
            53     return 0;
            54 }
            55 

            posted on 2012-02-14 22:22 jh818012 閱讀(123) 評(píng)論(0)  編輯 收藏 引用


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


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            久久激情亚洲精品无码?V| 久久国产精品无码网站| 中文字幕精品无码久久久久久3D日动漫 | 中文精品99久久国产| 久久精品国产99国产精品| 伊人色综合久久| 久久国产福利免费| 久久影视综合亚洲| 人妻无码精品久久亚瑟影视| 久久久久亚洲国产| 伊人久久大香线蕉av不卡| 精品国产乱码久久久久软件| 亚洲狠狠婷婷综合久久蜜芽| 午夜天堂精品久久久久| 麻豆亚洲AV永久无码精品久久| 国产亚洲精品美女久久久| 亚洲国产成人久久精品动漫| 91亚洲国产成人久久精品| 久久婷婷色综合一区二区| 久久天天躁夜夜躁狠狠躁2022| 久久青青草原亚洲av无码app| 国产精品视频久久| 久久国产精品一区| 精品一二三区久久aaa片| 九九99精品久久久久久| 久久se精品一区精品二区国产| 久久亚洲AV无码精品色午夜麻豆| 日日躁夜夜躁狠狠久久AV| 国产精品嫩草影院久久| 亚洲人成无码网站久久99热国产| 久久综合狠狠综合久久| 久久99国产精品成人欧美| 欧美黑人又粗又大久久久| 久久www免费人成看国产片| 亚洲午夜久久久影院| 精品国产91久久久久久久a| 久久国产热这里只有精品| 久久精品中文字幕一区| 久久久人妻精品无码一区| 久久精品国产99国产精品导航 | 久久精品国产第一区二区三区|