思路:
把它拆成两半 分别搜一发
两部分分别排好序
用two-pointers扫一遍 就可以了.
(读入也要用long long)
//By SiriusRen#include#include #include using namespace std;typedef long long ll;int n,len,top,f,r;ll m,s[1500500],s2[1500500],a[55],ans;void dfs(int x,ll wei){ if(wei>m)return; s[top++]=wei; for(int i=x+1;i<=len;i++){ dfs(i,wei+a[i]); }}int main(){ scanf("%d%lld",&n,&m); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); len=n/2; dfs(0,0); sort(s+1,s+top),r=top-1; for(int i=1;i m)r--; ans+=r+1; } printf("%lld\n",ans);}