class Solution { public: int maximumCostSubstring(string s, string chars, vector<int>& vals) { int size = s.size(); vector<int> dp(size); auto found = chars.find(s[0]); if(found == string::npos) dp[0] = s[0] - 'a' + 1; else dp[0] = vals[found]; int res = max(0,dp[0]); for(int i = 1;i < size;++i){ int value; found = chars.find(s[i]); if(found == string::npos) value = s[i] - 'a' + 1; else value = vals[found]; dp[i] = max(dp[i-1] + value,value); res = max(res,dp[i]); } return res; } };
标签:2606,int,res,开销,value,found,leetcode,dp,size From: https://www.cnblogs.com/uacs2024/p/18641482