F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Poker

Time 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
2 3 12 3 3 4 3 12 9 5 3
 

Sample Output
Case #1: 16 Case #2: 26
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:32:21, Gzip enabled