Content-Length: 288999 | pFad | http://github.com/ramtanniru/Leetcode/commit/43dcd82a2388611b50eadd5dd982ca46538f2d2c
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 62428bd commit 43dcd82Copy full SHA for 43dcd82
Oct-31-24.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def minimumTotalDistance(self, robot: List[int], factory: List[List[int]]) -> int:
3
+ def rec(i=0,j=0,limit=0):
4
+ nonlocal robot,factory
5
+ if i>=len(robot):
6
+ return 0
7
+ if j>=len(factory):
8
+ return float('inf')
9
+
10
+ if (i,j,limit) in dp:
11
+ return dp[(i,j,limit)]
12
13
+ notTake = rec(i,j+1,0)
14
15
+ take = float('inf')
16
+ if factory[j][1]>limit:
17
+ dist = abs(factory[j][0]-robot[i])
18
+ take = dist + rec(i+1,j,limit+1)
19
20
+ dp[(i,j,limit)] = min(take,notTake)
21
22
23
+ robot.sort()
24
+ factory.sort()
25
+ dp = defaultdict(int)
26
+ return rec()
Fetched URL: http://github.com/ramtanniru/Leetcode/commit/43dcd82a2388611b50eadd5dd982ca46538f2d2c
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy
0 commit comments