解题思路:
- 建立hash_map {{'l',4},{'o',3},{'v',2},{'e',1}},dp[i][j]=max(dp[i][j−1],dp[i−1][j])+check[v].
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin>>n>>m;
getchar();
unordered_map<char,int> check{{'l',4},{'o',3},{'v',2},{'e',1}};
vector<vector<int>> dp(n+1,vector<int>(m+1,0));
char v;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
scanf("%c",&v);
dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + check[v];
}
getchar();
}
cout<<dp[n][m]<<endl;
return 0;
}