0pts,help!

B3624 猫粮规划

love20110429 @ 2024-04-17 13:31:43

#include <iostream>
using namespace std;
int n,l,r,ans,a[1000000],w[1000000]; 
void dfs(int t){
    int sum=0;
    for (int i=1;i<=t-1;i++){
        sum+=w[i]*a[i];
    }
    if (sum>=r){
        return;
    }
    if (t==n+1){
        if (l<=sum&&sum<=r){
            ans++;
        }
        return;
    }
    for (int i=0;i<=1;i++){
        a[t]=i;
        dfs(t+1);
    }
    return;
}
int main(){
    cin>>n>>l>>r;
    for (int i=1;i<=n;i++){
        cin>>w[i];
    }
    dfs(1);
    cout<<ans;
    return 0;
}

by L_zaa_L @ 2024-04-17 14:21:18

@love20110429 if (sum>=r){ return; }大于等于改为大于。


by love20110429 @ 2024-04-17 18:52:28

@zaa 已A,thx


|