"CodeVS1983" equation problem

Source: Internet
Author: User

Description

There is an unfinished equation: 1 2 3 4 5 6 7 8 9=n space (1 front without spaces) can be filled in +,-, can also be blank. Programming to find out the total number of all scenarios in which the equation is formed after entering an integer N. Guaranteed to have a solution.

Input

Enter a number n.

Output

Outputs a number. The number of all scenarios.

Sample Input

108

Sample Output

15

Exercises

To find out what symbols to fill in, it is important to note that [1*2+3*4-5, be aware of the order of operations], so open a variable to save a +/-to the next +/-middle portion. The z in the code below is the function, the T-symbol.

Also note that DFS (1,0,1,1) below cannot be written as DFS (1,1,0,0), since this 1 at the beginning is equivalent to 0 plus (because 1 cannot be signed)

#include <iostream>#include<cstdio>using namespacestd;intN,ans;voidDfsintStepintAnsintZintt) {    if(Step = =9&&z) ans+ = z*T; if(Step = =9&& ans = = N) ans++; if(Step = =9)return; DFS (step+1, ans+z*t,step+1,1); DFS (step+1, ans+z*t,step+1,-1); DFS (step+1, ans,z*Ten+step+1, t);}intMain () {scanf ("%d",&N); DFS (1,0,1,1); printf ("%d", ANS);}

"CodeVS1983" equation problem

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.