TopcoderArchive
Archive
Algorithm problem

CardConcat

Problem statement, definition, constraints, and public examples.

Problem Statement

Time limit is 4 seconds.

You have a collection of cards. The cards have mutually distinct colors. Each card contains some positive integer. These integers are given in the int[] cards.

You like to build large integers by concatenating the numbers written on one or more of your cards. For example, if you have cards with numbers 123, 456 and 789, some of the numbers you can produce this way include 123456789, 789123456, 789456, and 456. Two ways of producing a number are distinct if they use a distinct sequence of cards, even if the produced number is the same.

Suppose you tried out all possible ways to produce a number, and for each of those ways you wrote down the integer produced. Calculate and return the sum of all those integers, modulo 10^9 + 7.

Definition

Class:
CardConcat
Method:
sum
Parameters:
int[]
Returns:
int
Method signature:
int sum(int[] cards)
(be sure your method is public)

Constraints

  • cards will contain between 1 and 100 elements, inclusive.
  • Each element of cards will be between 1 and 10^9, inclusive.

Examples

  1. {4, 23}
    Returns: 684
    The numbers you can generate are 4, 23, 234, and 423. Their sum is 684.
  2. {1, 1, 1}
    Returns: 735
    There are six distinct ways to produce the number 111, six distinct ways to produce the number 11, and three distinct ways to produce the number 1.
  3. {1, 1, 2, 3, 5, 8, 13}
    Returns: 721590587
  4. {1000, 1000, 2000, 3000, 5000, 8000, 13000}
    Returns: 427973430
Back to all problems