from typing import List


def solve(weights: List[int], profits: List[float], capacity: int) -> List[List[float]]:
    """
    Solves given knapsack instance with dynamic programming and returns solution matrix.
    :param weights: Weights of items
    :param profits: Profits of items
    :param capacity: Capacity of knapsack instance
    :return: Solution matrix as list of lists of floats representing the maximum possible profit in the cell
    """
    assert len(weights) == len(profits)
    n: int = len(weights)  # items are numbered 0 to n-1
    f: List[List[float]] = [[0 if weights[0] > c else profits[0] for c in range(capacity + 1)]]
    for j in range(1, n):
        f.append([f[j - 1][c] if weights[j] > c else max(f[j - 1][c], f[j - 1][c - weights[j]] + profits[j]) for c in
                  range(capacity + 1)])
    return f