当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5460:Poker

题目描述
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.
输入解释
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$.
输出解释
For each test case, you should print one non-negative integer as the total points you can get, in a line.
输入样例
2
3 12
3 3 4
3 12
9 5 3
输出样例
Case #1: 16
Case #2: 26
提示
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.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5460

最后修改于 2020-10-25T23:22:52+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000/2000MS(Java/Others) 65535/102400K(Java/Others)