dp(mask)
where mask
is a bitmask representing the set of tasks that have been completed.mask
is 0 (no tasks completed), return (1, 0) indicating one session is needed with 0 time spent.j
that is not completed in mask
:
a. Calculate the result of completing task j
by calling dp(mask - (1 << j))
.
b. Determine if adding task j
to the current session would exceed the session time, requiring a new session.
c. Update the minimum number of sessions and remaining time accordingly.dp(mask)
to avoid redundant calculations.dp((1<<n) - 1)[0]
, which represents completing all tasks.