2469: Little Y's Puzzle 1---swust Information Institute OJ

Source: Internet
Author: User

Title Description: http://www.oj.swust.edu.cn/problem/show/2469

Description
Recently, little Y has been fascinated by mathematics and is always thinking about various mathematical problems. One day, he accidentally spilled ink on the draft paper. What he can see now is "2?3?1?4" (? Indicates a place to see). Small Y's memory is good, he knows: 1, each? Only one of the three symbols is "+", "-", "=". 2. There is a total of only one "=". 3, the original formula must be an equation. Like "2+3-1=4" now he suddenly wondered how many possibilities there were to meet the above 3 requirements.
Input
multiple sets of inputs. The first row of each group has a number n. Represents a small y from left to right and can see n numbers altogether. (2<=n<=15) The second row of each group has n digits. Indicate what these n numbers are. Ensure that each number is a non-negative integer and less than 10^7.
Output
For each group, the output line, which has only one number, indicates how many possibilities satisfy the test instructions.
    • Sample Input
    • Raw
42 3 1 441 1 1 1
    • Sample Output
    • Raw
26
Hint
There must be only one symbol between the numbers, and there is no sign in front of the first number.

AC Code:

1#include <stdio.h>2 3 inta[ -];4 Chars[ -];5 intN;6 intFlag;7 intans;8 9 voidDFS (intLevel//possibility of Dfs search +-= appearingTen { One  A     if(level==n-1) -     { -         intI=0, l=a[0],r=0; the  -          while(s[i]!='='&&i<n-1) { -  -             if(s[i]=='+') l+=a[i+1]; +             Else if(s[i]=='-') l-=a[i+1]; -  +i++; A  at         } -  -          while(i<n-1) { -  -             if(s[i]=='+') r+=a[i+1]; -             Else if(s[i]=='-') r-=a[i+1]; in             Elser=a[i+1]; -  toi++; +          -         } the  *         if(L==r&&flag) ans++; $ Panax Notoginseng         return; -  the     } +  As[level]='+'; theDFS (level+1); +  -s[level]='-'; $DFS (level+1); $  -     if(flag)return; -  thes[level]='='; -flag=1;WuyiDFS (level+1); theflag=0; -  Wu } -  About intMain () $ { -      -      while(SCANF ("%d", &n)! =EOF) -     { A  +         inti; the  -ans=0; $  the          for(i=0; i<n;i++) scanf ("%d",&a[i]); the  theDFS (0); the  -printf"%d\n", ans); in  the     } the  About     return 0; the  the}

2469: Little Y's Puzzle 1---swust Information Institute OJ

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.