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

建议使用的浏览器:

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

4192:Guess the Numbers

题目描述
John has never been very good at maths. Due to his bad grades, his parents have sent him to the Academic Coalition of Mathematics (ACM). Despite the large amount of money his parents are spending on the ACM,
John does not pay much attention during classes. However, today he has begun to think about all the e ffort his parents are putting into his education, and he has started to feel somewhat. . . guilty. So he has made a decision: he is going to improve his maths grades!

However, no sooner had he resolved to pay attention than the lesson ended. So the only thing he has been able to do is to hurriedly copy the content of the blackboard in his notebook. Today, the teacher was explaining basic arithmetic expressions with unknowns. He vaguely remembers that his classmates have been substituting values into the unknowns to obtain the expressions' results. However, in all the hurry, John has only written down expressions, values and results in a messy fashion. So he does not know which value comes with each unknown, or which result goes with each expression.
That is the reason he needs your help: he wants to know, given an expression, some values and a result, whether it is possible or not to assign those values to the unknowns in order for the expression to evaluate to the given result. The particular assignment of values does not matter to John, as he wants to do it by himself. He only wants to know whether it is possible or not.
输入解释
Each test case in the input le consists of two lines:
 The fi rst line contains a sequence of natural numbers. The first one (1<=n<=5) is the number of unknowns that will occur in the expression. It is followed by a sequence of n integers v1 ... vn (0<=vi<=50), which are the values to be assigned to the unknowns. Finally, there is an integer m (0<=m<=1000) representing the desired result of the evaluation of the expression.
 The second line contains an arithmetic expression composed of lowercase letters (a-z), brackets (( and )) and binary operators (+, -, *). This expression will contain n unknowns, represented by n di fferent lowercase letters, without repetitions. The expression will not contain any blanks and will always be syntactically correct, i.e. it is just an unknown or has the form (e1 op e2 ), where e1 and e2 are expressions and op is one of the three possible binary operators.
The input will finish with a dummy test case of just one line containing 0 0, which must not be processed.
输出解释
For each test case, print a single line with YES if there exists an assignment of the values v1 . . . vn to the unknowns such that the expression evaluates to m, and NO otherwise. Notice that each value vi must be assigned to exactly one unknown.
输入样例
3 2 3 4 14
((a+b)*c)
2 4 3 11
(a-b)
1 2 2
a
0 0
输出样例
YES
NO
YES
来自杭电HDUOJ的附加信息
Recommend lcy

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

题目来源 SWERC 2011

源链接: HDU-4192

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

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/32768K(Java/Others)