All submissions for this problem are available.
The Grayson family had a long history of family feuds. The only thing they had in common was that they were related by blood. In one final attempt to unite his family, Mr. Grayson comes up with this idea in the hope that his family would work together and rekindle what was once lost. Their father on his death bed gave his children a word each. Each letter in a word represents a number. The sum of the first n-1 words must total the final word (n being the number of children). The final word, given to the eldest son represents the family’s bank account containing their inheritance of millions of dollars.
The same letter throughout the string of words must be represented by only one number, and no letter is used to represent more than one number. Furthermore, the leftmost digit of any number is not allowed to be a zero.
Write a program to help the Grayson family get their inheritance.
Your program should first accept a number n, which will indicate the number of lines to follow. The following n lines will each contain a word of no more than 10 characters.
Your output should consist of an integer (The total number of solutions) if you believe there to be one, or the word 'Impossible' if you do not. If you find a solution and believe it to be the only one, you should only print out 'Unique'.
- 3 ≤ n ≤ 6
Input: 4 ABCDE CDEFG EFGHI AJCGJA Output: 4
12345 + 34567 + 56789 = 103701
12345 + 34569 + 56987 = 103901
12365 + 36547 + 54789 = 103701
12365 + 36549 + 54987 = 103901
Total 4 possible ways.
Note : The reference for this problem has been taken from : British Information Olympiad
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.