KKX Sequence (CDOJ1644)

KKX Sequence

Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 142 Tried: 754

Description

KKX likes to play with sequences and find interesting things. For an integer sequence A[1], A[2], …, A[N], he subtracts every adjacent two elements to get another sequence of length N-1, B[1], B[2], …, B[N-1], where B[i] = A[i] – A[i+1], i = 1, 2, …, N-1. Keep on this method until only one element left. Obviously, for a sequence this number is unique.

KKX wants to know if he can rearrange the elements in the initial sequence A in any order, what is maximal number left using the method above?

Please use 64-bit integers(long long in C/C++) to do calculation in this problem. And use the "%lld" specificator to read or write 64-bit integers in C/C++.

Input

There will be multiple test cases. The first line of the input is an integer T (T <= 100) indicating the number of test cases.
For each test case an integer N (1 <= N <= 50) comes first indicating the number of elements in the initial sequence A. The next line contains N integers with absolute value within 1000.

Output

Print “Case #k: x” in a single line for each test case, in which k represents the case number which starts from 1, and x is the maximal number left.

Simple Input

2
3
1 1 -1
5
2 1 5 -4 2

Simple Output

Case #1: 4
Case #2: 46

Source

10th UESTC Programming Contest Preliminary




 解法,利用杨辉三角。把第N行的数第一个为正,第二个为负,第三个为正的一行的数取出排序与输入的数进行排序后进行点乘即可。

你可能感兴趣的:(其它)