input: def solve_knapsack(items: List[Tuple[int, int]], capacity: int) -> int:
      """Find the optimal solution to solve a knapsack problem using dynamic programming.
      >>> solve_knapsack([(60, 10), (100, 20), (120, 30)], 50)
      220
      """
      n = len(items)
      dp = [[0] * (capacity + 1) for _ in range(n + 1)]
      
      for i in range(1, n + 1):
          for w in range(1, capacity + 1):
              if items[i-1][1] <= w:
                  dp[i][w] = max(dp[i-1][w], dp[i-1][w - items[i-1][1]] + items[i-1][0])
              else:
                  dp[i][w] = dp[i-1][w]
                  
      return dp[n][capacity]
output:     n = len(items)
      dp = [[0] * (capacity + 1) for _ in range(n + 1)]
      
      for i in range(1, n + 1):
          for w in range(1, capacity + 1):
              if items[i-1][1] <= w:
                  dp[i][w] = max(dp[i-1][w], dp[i-1][w - items[i-1][1]] + items[i-1][0])
              else:
                  dp[i][w] = dp[i-1][w]
                  
      return dp[n][capacity]