比赛 NOIP2023模拟赛1 评测结果 AAWWWWTTTT
题目名称 博士的密码 最终得分 20
用户昵称 ムラサメ 运行时间 4.186 s
代码语言 C++ 内存使用 2.94 MiB
提交时间 2023-11-13 12:59:56
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long n,key1,ans=0;
  4. long long a[45];
  5. void dfs(long long x,long long w){
  6. if(w==key1){
  7. ans++;
  8. return;
  9. }
  10. if(x>n+1){
  11. return;
  12. }
  13. dfs(x+1,w+a[x]);
  14. dfs(x+1,w);
  15. }
  16. int main(){
  17. freopen("password1.in","r",stdin);
  18. freopen("password1.out","w",stdout);
  19. ios::sync_with_stdio(0);
  20. cin.tie(0);
  21. cout.tie(0);
  22. cin>>n>>key1;
  23. memset(a,0,sizeof(a));
  24. for(int i=1;i<=n;i++){
  25. cin>>a[i];
  26. }
  27. dfs(1,0);
  28. cout<<ans<<endl;
  29. return 0;
  30. }