比赛 |
NOIP2023模拟赛1 |
评测结果 |
AAWWWWTTTT |
题目名称 |
博士的密码 |
最终得分 |
20 |
用户昵称 |
ムラサメ |
运行时间 |
4.186 s |
代码语言 |
C++ |
内存使用 |
2.94 MiB |
提交时间 |
2023-11-13 12:59:56 |
显示代码纯文本
- #include<bits/stdc++.h>
- using namespace std;
- long long n,key1,ans=0;
- long long a[45];
- void dfs(long long x,long long w){
- if(w==key1){
- ans++;
- return;
- }
- if(x>n+1){
- return;
- }
- dfs(x+1,w+a[x]);
- dfs(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];
- }
- dfs(1,0);
- cout<<ans<<endl;
- return 0;
- }