NOIP '08 P2 - Expression by Matches

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem types

Given n matchsticks, how many equations of the form A+B=C can you spell out? A, B, and C in the equation are integers spelled out with matchsticks (if the number is non-zero, the highest digit cannot be 0). The spelling of numbers 0-9 with matchsticks is shown in the figure:

Note:

  1. The plus sign and the equal sign each require two matchsticks.
  2. If AB, then A+B=C and B+A=C are regarded as different equations (A,B,C0)
  3. All n matchsticks must be used.

Input Specification

One line: an integer n (n24).

Output Specification

One line, indicating the number of different equations that can be spelled.

Sample Input 1

Copy
14

Sample Output 1

Copy
2

Explanation of Sample Output 1

The 2 equations are 0+1=1 and 1+0=1.

Sample Input 2

Copy
18

Sample Output 2

Copy
9

Explanation of Sample Output 2

The 9 equations are: 0+4=40+11=111+10=112+2=42+7=94+0=47+2=910+1=1111+0=11


Comments

There are no comments at the moment.