题解 | #神奇的口袋#
神奇的口袋
https://www.nowcoder.com/practice/9aaea0b82623466a8b29a9f1a00b5d35
#include <iostream> using namespace std; int arr[45]; int DFS(int num,int n){ if(num==0){ return 1; } if(num<0 || n==0){ return 0; } return DFS(num-arr[n],n-1) +DFS(num,n-1); } int main() { int n; cin>>n; for(int i=1;i<=n;i++){ cin >> arr[i]; } cout<<DFS(40,n)<<endl; }