wa求助

B3624 猫粮规划

fengsongyang0428 @ 2024-05-12 16:17:43

#include <bits/stdc++.h>
using namespace std;
int n,l,r,a[50],cnt=0;
void dfs(int i,int ans) {
    if(l<=ans&&ans<=r) {
        cnt++;
    }
    if (ans>r||i==n) {
        return;
}
    for (int j=i+1;j<=n;j++) {
        if(ans+a[j]<r){
        ans+=a[j];
        dfs(j,ans);
        ans-=a[j];
        }
    }
}
int main(){
    cin>>n>>l>>r;
    for(int i=0;i<n;i++)cin>>a[i];
        dfs(0,0);
    cout<<cnt;
    return 0;
}

by meifan666 @ 2024-07-21 19:31:26

@fengsongyang0428 为什么你输入是0到n-1,深搜却搜到n?

改后AC,求关


|