1114. The Magic Pocket

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.