#P1464. Recursive Function Evaluation: w(a, b, c)
Recursive Function Evaluation: w(a, b, c)
Recursive Function Evaluation: w(a, b, c)
This problem asks you to implement a recursive function \(w(a,b,c)\) defined as follows:
- If \(a \le 0\) or \(b \le 0\) or \(c \le 0\), then \(w(a,b,c)=1\).
- If \(a>20\) or \(b>20\) or \(c>20\), then \(w(a,b,c)=w(20,20,20)\).
- If \(a<b\) and \(b<c\), then \(w(a,b,c)=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c)\).
- Otherwise, \(w(a,b,c)=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1)\).
Note: For example, even though \(w(30, -1, 0)\) satisfies both the condition for returning 1 and for calling \(w(20,20,20)\), you must follow the order of conditions given (i.e. the very first applicable condition), so the answer is 1. Since the recursion can be extremely deep (e.g. when \(a=b=c=15\)), an efficient solution (using memoization or other methods) is required.
inputFormat
The input consists of several test cases. Each test case is given on a separate line containing three integers \(a\), \(b\), \(c\) separated by spaces. The input terminates with a line containing "-1 -1 -1", which should not be processed.
outputFormat
For each test case, print the result in the following format:
w(a, b, c) = result
Make sure to follow the exact format including spaces and punctuation.
sample
1 1 1
-1 -1 -1
w(1, 1, 1) = 2