题解 | #字母收集#
字母收集
https://www.nowcoder.com/practice/9740ce2df0a04399a5ade1927d34c1e1
#include <iostream> using namespace std; const int N = 510; char a[N][N]; int dp[N][N]; int main() { int n, m; cin >> n >> m; for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++){ cin >> a[i][j]; } for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++){ if(a[i][j] == 'l') dp[i][j] = max(dp[i - 1][j] + 4, dp[i][j - 1] + 4); else if(a[i][j] == 'o') dp[i][j] = max(dp[i - 1][j] + 3, dp[i][j - 1] + 3); else if(a[i][j] == 'v') dp[i][j] = max(dp[i - 1][j] + 2, dp[i][j - 1] + 2); else if(a[i][j] == 'e') dp[i][j] = max(dp[i - 1][j] + 1, dp[i][j - 1] + 1); else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } cout << dp[n][m] << endl; }