蒟蒻求解,如何剪枝

P1478 陶陶摘苹果(升级版)

jzcrq @ 2020-03-25 10:41:40

#include<bits/stdc++.h>
using namespace std;
int main (){
    int apples,str,chair,hand,high[5001]={0},waste[5001]={0},can[5001]={0},able=0,get,bag=0;
    cin>>apples>>str>>chair>>hand;
    get=chair+hand;
    for (int a=1;a<=apples;a++){
        cin>>high[a]>>waste[a];
        if (high[a]<=get) {
            able++;
            can[able]=waste[a];
        }
    }
    for (int b=1;b<=able;b++){
        int c,d,e;
        d=b;
        c=b-1;
        while (c!=1){
            if (can[d]<can[c]){
                e=can[c];
                can[c]=can[d];
                can[d]=e;
            }
            d--;
            c--;
        } 
    }
    for (int f=1;f<=able;f++){
        str-=can[f];
        if (str>=0) bag++;
    }
    cout<<bag;
}

rt


by jzcrq @ 2020-03-25 10:42:39

也可能是其他问题,~~排序忘了个精光~~


by 594wyx @ 2020-03-25 10:43:51

@lscrq

做这种题用这么高大上的方法?


by Forest_Prince @ 2020-03-25 10:47:21

sort一下不香嘛


by Karrγ5307 @ 2020-03-25 10:54:06

这道题不是dp,是贪心


by Karrγ5307 @ 2020-03-25 10:54:20

@lscrq


|