题解 | #字母收集#
字母收集
http://www.nowcoder.com/practice/9740ce2df0a04399a5ade1927d34c1e1
while True:
try:
n, m = map(int, input().split())
l = []
for _ in range(n):
l.append(list(input()))
dp = [[0 for i in range(m + 1)] for j in range(n + 1)] # dp[i][j]表示当前当前位置所能收集的最大分数
for i in range(1, n + 1):
for j in range(1, m + 1):
if l[i-1][j-1] == 'l':
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + 4
elif l[i-1][j-1] == 'o':
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + 3
elif l[i-1][j-1] == 'v':
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + 2
elif l[i-1][j-1] == 'e':
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
print(dp[n][m])
except:
break