|
||||||||||
PokerTime Limit: 3000/2000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 350 Accepted Submission(s): 91 Problem Description Given $N$ cards in poker and an integer $Q$. Choose several cards and form an expression, whose result equals to $Q$, via addition, subtraction, multiplication and division. Each expression, which meet the requirements, with $x$ cards can earn $x^2$ points. The intermediate value for each step must be an non-negative integer. You need to calculate how many points you can get. Your attention, two expressions are different if and only if the prefix expressions of them are different. In others words, if an expression can transform to another through commutative law or associative law, these two expressions are considered distinct. Moreover, two cards with the same number are also viewed different. Input There is one integer $T~(1<T\le 13)$ in the beginning of input, which means that you need to process $T$ test cases. In each test case, two integers $N~(1<N\le 8)$ and $Q~(0\le Q\le 32)$, as the problem described above, are shown in the first line. And in the second line are $N$ integers $A_i~(1\le A_i\le 13)$, indicating $N$ numbers on the cards. You may assume that there are at most two test case containing $N=8$. Output For each test case, you should print one non-negative integer as the total points you can get, in a line. Sample Input
Sample Output
Hint In the first test case, there are four expressions: 3(A) กม 4 = 12 4 กม 3(A) = 12 3(B) กม 4 = 12 4 กม 3(B) = 12 3(A) is the first card of three, and 3(B) is the second card of three. Each expression earn 4 points, so the answer is 16. in the second test case, there are four expression: 9 + 3 = 12 3 + 9 = 12 (9 - 5) กม 3 = 12 3 กม (9 - 5) = 12 The form two expressions cost 4 points each, and the latter two cost 9 points each. Thus, the answer is 26. Source | ||||||||||
|