#include <iostream> using namespace std; //(cur_v, index, select):当(40, i, sel)时,新出现一种选择方式,sel++ int items[20], cur_v = 0, selection = 0, n; int visited[20]; void DFS(int index){ if(cur_v == 40) { //成功得到物品条件 selection++; return ; } //剪枝 for(int i=index; i<n; ++i){ if(visited[i] || (cur_v+items[i])>40) continue; visited[i] = 1; cur_v += items[i]; DFS(i+1); visited[i] = 0; cur_v -= items[i]; } } int main() { cin>>n; for(int i=0; i<n; ++i){ cin>>items[i]; } for(int i=0; i<n; ++i){ visited[i] = 0; } DFS(0); cout<<selection<<endl; }