UVA 11076

import java.io.*;
import java.util.*;
import java.math.*;

public classMain {
	
	static final int MAXN = 13;
	
	int A[] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; // 阶乘
	int a[] = new int[10], n, x;
	
	// 大整数应用注意,Java中没有unsigned,用BigInteger代替c++中的unsigned long long
	int solve(int x) {
		int ans = A[n - 1];
		for (int i = 0; i < 10; i++) {
			if (a[i] > 1) {
				if (i == x) ans /= A[a[i] - 1];
				else ans /= A[a[i]];
			}
		}
		return ans; // 组合值
	}
	
	void run() {
		while (true) {
			n = cin.nextInt();
			if (n == 0) break;
			Arrays.fill(a, 0);
			for (int i = 0; i < n; i++) {
				x = cin.nextInt();
				a[x]++;
			}
			BigIntegertemp, ans;
			temp = ans = BigInteger.ZERO;
			for (int i = 0; i < 10; i++) {
				if (a[i] > 0) {
					temp = temp.add(BigInteger.valueOf(i * solve(i)));
				}
			}
			for (int i = 0; i < n; i++) 
				ans = ans.multiply(BigInteger.valueOf(10)).add(temp);
			System.out.println(ans);
		}
		
	}               
	
	public static void main(String[] args) {
		Mainsolved = new Main();
		solved.run();
	}
	
	static InputStreaminputStream = System.in;
	static InputReadercin = new InputReader(inputStream);
	
//	Scanner cin = new Scanner(new BufferedInputStream(System.in));
	
}


classInputReader { 

    private InputStreamstream; 
    private byte[] buf = new byte[1024]; 
    private int curChar; 
    private int numChars; 

    public InputReader(InputStreamstream) { 
        this.stream = stream; 
    } 

    public int read() { 
        if (numChars == -1) 
            return -1; 
            //throw new InputMismatchException(); 
        if (curChar >= numChars) { 
            curChar = 0; 
            try { 
                numChars = stream.read(buf); 
            } catch (IOExceptione) { 
                throw new InputMismatchException(); 
            } 
            if (numChars <= 0) 
                return -1; 
        } 
        return buf[curChar++]; 
    } 

    public int nextInt() { 
        int c = read(); 
        if (c == -1) 
            return -1; 
        while (isSpaceChar(c)) 
            c = read(); 
        int sgn = 1; 
        if (c == '-') { 
            sgn = -1; 
            c = read(); 
        } 
        int res = 0; 
        do { 
            if (c < '0' || c > '9') 
                throw new InputMismatchException(); 
            res *= 10; 
            res += c - '0'; 
            c = read(); 
        } while (!isSpaceChar(c)); 
        return res * sgn; 
    } 
     
    public Stringnext() {   
        StringBuilderstr = new StringBuilder();   
        int ch;   
        while (isSpaceChar(ch = read()));   
        if (ch == -1)   
            return null;   
        do {   
            str.appendCodePoint(ch);   
        } while (!isSpaceChar(ch = read()));   
        return str.toString();   
    }  
     
    public static boolean isSpaceChar(int c) { 
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; 
    } 

    public char nextCharacter() { 
        int c = read(); 
        while (isSpaceChar(c)) 
            c = read(); 
        return (char) c; 
    } 

} 

posted on 2013-02-19 21:22  Sure_Yi  阅读(192)  评论(0编辑  收藏  举报

导航