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