题目
分析
代码
1 #include<iostream>
2 #define ll long long
3 using namespace std;
4 ll a[50],s[50];
5 ll n,c;
6 ll ans=0;
7 void dfs(ll p,ll sum)
8 {
9 if (sum>c||s[p-1]+sum<=ans)
10 return;
11 ans=max(ans,sum);
12 for (int i=p-1;i>=1;i--)
13 {
14 sum+=a[i];
15 dfs(i,sum);
16 sum-=a[i];
17 }
18 }
19 int main ()
20 {
21 cin>>n>>c;
22 ll x;
23 for (int i=1;i<=n;i++)
24 cin>>a[i];
25 for (int i=1;i<=n;i++)
26 s[i]=s[i-1]+a[i];
27 dfs(n+1,0);
28 cout<<ans;
29 return 0;
30 }