Created
November 11, 2013 13:09
-
-
Save cocodrips/7412950 to your computer and use it in GitHub Desktop.
SRM583 Div1 Easy わーしゃるなふろいどさんで試す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TravelOnMars2: | |
def minTimes(self, range, startCity, endCity): | |
N = len(range) | |
INF = 1000000 | |
dp = [[INF for _ in xrange(N)] for _ in xrange(N)] | |
for i in xrange(N): | |
for j in xrange(N): | |
l = (i - j + N) % N | |
r = (j - i + N) % N | |
if min(l, r) <= range[i]: | |
dp[i][j] = 1 | |
print dp | |
for k in xrange(N): | |
for i in xrange(N): | |
for j in xrange(N): | |
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) | |
return dp[startCity][endCity] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment