记录编号 584551 评测结果 AAAAAAAAAA
题目名称 博士的密码 最终得分 100
用户昵称 Gravatarムラサメ 是否通过 通过
代码语言 C++ 运行时间 0.061 s
提交时间 2023-11-13 16:22:09 内存使用 1.18 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long n,key1,ans=0;
long long a[45];
map<long long,int> mp;
void dfsfront(int x,long long w){
	if(x==n/2){
		mp[w]++;
		return;
	}
	dfsfront(x+1,w+a[x+1]);
	dfsfront(x+1,w);
}
void dfsback(int x,long long w){
	if(x==n){
		ans+=mp[key1-w];
		return;
	}
	dfsback(x+1,w+a[x+1]);
	dfsback(x+1,w);
}
int main(){
	freopen("password1.in","r",stdin);
	freopen("password1.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>key1;
	memset(a,0,sizeof(a));
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfsfront(0,0);
	dfsback(n/2,0);
	cout<<ans<<endl;
	return 0;
}