WA求助

B3624 猫粮规划

Poetry_and_Distance @ 2024-08-29 15:03:38

#include <bits/stdc++.h>

using namespace std;

int a[45], n, l, r, ans = 0;

void dfs(int u, int sum)
{
    if (u > n)
    {
        if (sum >= l && sum <= r)
            ++ans;
        return;
    }
    if (sum < l && sum + a[u] <= r)
        dfs(u + 1, sum + a[u]);
    dfs(u + 1, sum);
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> l >> r;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    dfs(1, 0);
    cout << ans << endl;
    return 0;
}

by Ke9_qux @ 2024-08-29 15:12:13

@Poetry_and_Distance 第15行sum<l去掉


by Poetry_and_Distance @ 2024-09-03 20:59:56

@Ke9_qux 已回关


|