Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:25
Show Gist options
  • Save cocodrips/7fb85990e20e8ce4c220 to your computer and use it in GitHub Desktop.
Save cocodrips/7fb85990e20e8ce4c220 to your computer and use it in GitHub Desktop.
TCO2015 2C easy
class YetAnotherCardGame:
def maxCards(self, petr, snuke):
petr = list(petr)
snuke = list(snuke)
petr.sort()
snuke.sort()
turn = min(len(petr) * 2, len(snuke) * 2)
#dp[turn][max] = length
dp = [[0 for _ in xrange(101)] for _ in xrange(turn + 1)]
cards = [snuke, petr]
for i in xrange(1, turn + 1):
for j in xrange(101):
for p in cards[i & 1]:
if p > j: # おける
dp[i][p] = max(dp[i - 1][j] + 1, dp[i][p])
dp[i][j] = max(dp[i - 1][j], dp[i][j])
ans = 0
for i in xrange(101):
ans = max(ans, dp[turn][i])
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment