Last active
December 13, 2015 09:28
-
-
Save tsu-nera/651c4c24c865e89c3965 to your computer and use it in GitHub Desktop.
TCCC 2003 Round 4 Level1
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
| # -*- coding: utf-8 -*- | |
| import math,string,itertools,fractions,heapq,collections,re,array,bisect | |
| class ChessMetric: | |
| def howMany(self, size, start, end, numMoves): | |
| dx = [1, 1, 1, 0, -1, -1, -1, 0, 2, 1, -1, -2, -2, -1, 1, 2] | |
| dy = [1, 0, -1, -1, -1, 0, 1, 1, -1, -2, -2, -1, 1, 2, 2, 1] | |
| dp = [[[0 for i in range(55)] for j in range(100)] for k in range(100)] | |
| dp[start[0]][start[1]][0] = 1 | |
| for i in range(1, numMoves + 1): | |
| for x in range(size): | |
| for y in range(size): | |
| for j in range(16): | |
| nx = x + dx[j] | |
| ny = y + dy[j] | |
| if nx >= 0 and ny >= 0 and nx < size and ny < size: | |
| dp[nx][ny][i] += dp[x][y][i - 1] | |
| return dp[end[0]][end[1]][numMoves] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment