Untitled
unknown
plain_text
2 years ago
744 B
2
Indexable
def getMaxRequests(bandwidth, request, total_bandwidth): n = len(bandwidth) dp = [[0] * (total_bandwidth + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in range(total_bandwidth + 1): dp[i][j] = dp[i - 1][j] # Exclude the current endpoint if j >= bandwidth[i - 1]: # Include the current endpoint if it fits in the remaining bandwidth dp[i][j] = max(dp[i][j], request[i - 1] + dp[i - 1][j - bandwidth[i - 1]]) return dp[n][total_bandwidth] # Example usage bandwidth = [200, 100, 350, 50, 100] request = [270, 142, 450, 124, 189] total_bandwidth = 500 result = getMaxRequests(bandwidth, request, total_bandwidth) print(result)
Editor is loading...