← 返回 citadel 的题目列表Implement Recursive Task with Memorization
类型:online_judge
Using object-oriented programming, implement a task that supports recursion and memorization. Requirements:
Create a Task class supporting recursive computation of dependencies.
Implement a compute method that first computes all dependencies and then aggregates results using a compute_fn.
Extend Task class by creating Number for numeric tasks and Add to implement addition of two tasks.
Optimize the Fib class for Fibonacci number computation using memorization.
Provide test cases to ensure correct implementation.
Example Input:
Add(Add(Number(1), Number(2)), Number(3)).compute()
Fib(10).compute()
Data Constraints:
Ensure to compute Fibonacci(100) efficiently.
Example
Input
print(Add(Number(5), Number(10)).compute())