Content-Length: 288999 | pFad | http://github.com/ramtanniru/Leetcode/commit/43dcd82a2388611b50eadd5dd982ca46538f2d2c

A1 2463 · ramtanniru/Leetcode@43dcd82 · GitHub
Skip to content

Commit 43dcd82

Browse files
committed
2463
1 parent 62428bd commit 43dcd82

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Oct-31-24.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return dp[(i,j,limit)]
22+
23+
robot.sort()
24+
factory.sort()
25+
dp = defaultdict(int)
26+
return rec()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ramtanniru/Leetcode/commit/43dcd82a2388611b50eadd5dd982ca46538f2d2c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy