题目描述
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],ans = 0;
void dfs(int n,int m){
if(m == 0){
ans++;
return ;
}
if(n < 0 || m < 0) return ;
//如果倒数第n样菜拿的话
dfs(n-1,m-a[n]);
//如果倒数第n样菜不拿的话
dfs(n-1,m);
}
int main(){
cin>>n>>m; //总共M元
for(int i = 1;i<=n;i++){
cin>>a[i];
}
dfs(n,m);
cout<<ans<<endl;
return 0;
}