← 返回 twosigma 的题目列表Maximum Product Path in a Complete Directed Graph
类型:qbank
Given a complete directed graph with positive edge weights, find the no-repeated-node path that maximizes the product of edge weights. The candidate recognized the exponential nature and considered log-transform plus bitmask DP.
Requirements
Given a directed complete graph where every edge has positive weight, find a path with no repeated nodes that maximizes the product of edge weights.
The exact start/end constraints were not fully specified, so clarify:
Whether the start and end nodes are fixed.
Whether the path must visit all nodes or may stop early.
Whether edge weights can be less than, equal to, or greater than 1.
Whether the expected output is the maximum product, the path, or both.
Notes
Taking logs converts product maximization into sum maximization, which makes the objective additive.
If start/end and visit constraints are fixed and n is small, bitmask DP over (mask, last) is the natural exact approach.
If the path may be arbitrary length with all positive weights, the optimal stopping condition depends on whether weights below 1 are allowed; do not assume Hamiltonian path unless stated.
A brute-force enumeration is acceptable as a baseline for very small n, but the interviewer likely expects a sharper DP framing.
Preparation
Implement bitmask DP for maximum-weight Hamiltonian path after log-transform.
Practice clarifying product-path constraints before coding; tiny wording differences change the problem class.
Review why positive-product objectives are numerically safer in log space.