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 A \neq B, then A + B = C and B + A = C are regarded as different equations (A,B,C\geq 0)
  3. All n matchsticks must be used.

Input Specification

One line: an integer n (n \leq 24).

Output Specification

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

Sample Input 1

14

Sample Output 1

2

Explanation of Sample Output 1

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

Sample Input 2

18

Sample Output 2

9

Explanation of Sample Output 2

The 9 equations are: \displaystyle \begin{align*}
0+4&=4 \\
0+11&=11 \\
1+10&=11 \\
2+2&=4 \\
2+7&=9 \\
4+0&=4 \\
7+2&=9 \\
10+1&=11 \\
11+0&=11
\end{align*}


Comments

There are no comments at the moment.