题解 | #神奇的口袋#
神奇的口袋
http://www.nowcoder.com/practice/9aaea0b82623466a8b29a9f1a00b5d35
#include<iostream>
#include<algorithm>
using namespace std;
int cnt = 0;
void dfs(int v[],int n,int total,int pos){
if(total == 40){
cnt++;
return;
}
else
for(int i = pos;i < n;++i)
dfs(v,n,total + v[i],i + 1);
}
int main()
{
int n;
cin >> n;
int *v = new int[n];
for(int i = 0;i < n;++i)
cin >> v[i];
sort(v,v + n);
dfs(v,n,0,0);
cout << cnt;
}