Last active
August 29, 2015 14:02
-
-
Save niyarin/61378de5389b6e2f712e to your computer and use it in GitHub Desktop.
This file contains 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
t,w = raw_input().split(" ") | |
T,W = int(t),int(w) | |
apple_data = [] | |
for i in range(int(T)): | |
apple_data.append(input()-1) | |
note= [[-1 for j in range(T) ] for i in range(W + 1)] | |
def Foo(area,cnt,state): | |
on_get = 0 | |
if note[cnt][area] != -1: | |
return note[cnt][area] | |
if apple_data[area] == state: | |
on_get = 1 | |
if (area == T-1): | |
return on_get | |
if (cnt == W): | |
note[cnt][area] = Foo(area + 1,cnt,state) + on_get | |
else: | |
note[cnt][area] = max(Foo(area+1,cnt,state) + on_get,Foo(area + 1,cnt + 1,state^1) + on_get) | |
return note[cnt][area] | |
print max(Foo(0,0,0),Foo(0,1,1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment