精華區beta Marginalman 關於我們 聯絡資訊
1255. Maximum Score Words Formed by Letters 今天是hard 紀錄所有可能的組合算一個最大值 重複的跳過 不過一開始寫成flag = 害我卡住不知道哪裡錯== class Solution { public: int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) { unordered_set<string> st; vector<pair<string, int>> dp; string abc(26, 0); for(char c : letters){ abc[c - 'a']++; } dp.push_back({string(26, 0), 0}); int ans = 0; string s(26, 0); for(int i = 0; i < words.size(); i++){ for(int j = dp.size() - 1; j >= 0; j--){ bool flag = false; pair<string, int> p = dp[j]; for(char c : words[i]){ p.first[c - 'a']++; flag |= p.first[c - 'a'] > abc[c - 'a']; p.second += score[c - 'a']; } if(flag) continue; if(!st.count(p.first)){ dp.push_back(p); st.emplace(p.first); if(p.second > ans){ ans = p.second; s = p.first; } } } } return ans; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.36.41.116 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1716520582.A.F21.html
DJYOSHITAKA: 大濕... 05/24 11:17
sustainer123: 大師 05/24 11:22
yam276: 我獨自刷題 05/24 11:23
orangeNoob: 大師 05/24 12:47
family2909: 別卷了 05/24 13:32
sixB: 大師 05/24 15:14