Campus Bikes II
On a campus represented as a 2D grid, there areNworkers andMbikes, withN <= M. Each worker and bike is a 2D coordinate on this grid.
We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.
The Manhattan distance between two pointsp1andp2isManhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.
Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.
Example 1:

Example 2:

Note:
0<= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1]<1000All worker and bike locations are distinct.
1<= workers.length<= bikes.length<= 10
分析
dp[worker][state]
因为每个worker可以选N个车,所以用bit 做状态。类似 can I win
注意这里set和get用法
DFS
Last updated
Was this helpful?