Algebra ExpressProblem code: ACMKANPE |
All submissions for this problem are available.
Mim is a high school algebra teacher. Just last week, she taught her students how to evaluate an expression. For example, if
r = a × (b + c) ? d × e
Given the values of a, b, c, d and e, they can evaluate r.
Now, to test how well her students are able to do these arithmetic, she has to prepare some test. But, she do this every year, and each time she has to make same type of questions. That made her a little bored. She thinks that evaluating an expression only depends on the position of operators and variables, not the variables itself. For example in the expression above, for all possible values of a, b, c, d and e, they will all be equally hard to evaluate.
She has made some generic expressions, and a set of values, which she may use in any order (e.g. one time she may use a = 2, b = 5, another time she may use a = 5, b = 2). Now, she wants to know, the number of possible ways to assign these values, so that, the value of the expression lies within a specified limit.
Input
First line contains T, the number of test cases.
Each test case starts with three integers N(2 ? N ? 12), l, h (?1012 ? l ? h ? 1012), the number of variables, lower limit and the upper limit of the acceptable expression values.
Next line contains N integers ai(0 ? ai ? 9), the value of the variables she will be using in the exam.
Next line contains the expression, where each variable is represented as ‘x’. The expression will be well formed, and will contain only the symbols ‘+’, ‘-’, ‘*’,‘(’,‘)’ and ‘x’.
Output
For each test case, output the number of different assignments, that produce results within the limit [l, h].
Note that, you will be replacing each ‘x’ with a value aj(1 ? j ? N). Each aj have to be used exactly once. Two assignments are considered the same, if, after replacing all ‘x’, the expressions look the same.
Sample input and output
|
|
|
|
stdin
|
stdout
|
|
|
|
|
3 3 1 10 1 2 5 x+x*x 4 1 10 1 2 2 5 (x+x)*(x-x) 4 1 100 1 1 1 1 x*(x-(x*x)) |
4
4 0 |
|
|
|
| Author: | admin |
| Date Added: | 27-10-2010 |
| Time Limit: | 20 sec |
| Source Limit: | 50000 Bytes |
| Languages: | C, C99 strict, CLOJ, CPP 4.3.2, F#, GO, JAVA, PERL6, PYTH 3.1.2, TEXT |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions
