-
Title Description:
-
There is a magical pocket, the total volume is 40, with this pocket can be used to change some items, the overall product of these items must be 40. John now has n items to get, each of which is a1,a2......an in volume. John can choose from these items, if the total volume of the selected object is 40, then using this magical pocket, John will be able to get these items. The question now is how many different ways John has to choose items.
-
Input:
-
The first line of input is a positive integer n (1 <= n <= 20), indicating the number of different items. Next n rows, each line has a positive integer between 1 and 40, giving the value of a1,a2......an.
-
Output:
-
Outputs the number of different ways to select items.
-
Sample input:
-
3202020
-
Sample output:
-
3
#include <iostream>using namespacestd;inta[ +];intN,ans;voidDfsintIintsum) { if(sum> +)return; if(sum== +) {ans++; return ; } if(i>=n)return; if(sum< +) {DFS (i+1, Sum+a[i]);//Select A[i]DFS (i+1, sum);//do not select A[i] }}intMain () { while(cin>>N) { for(intI=0; i<n;i++) cin>>A[i]; Ans=0; DFS (0,0); cout<<ans<<Endl; } return 0;}
The magic of this problem is just pressing in the third question of the second interview.
1114. The Magic Pocket