Re: [閒聊] 每日leetcode

看板Marginalman作者時間4周前 (2024/05/24 11:16), 編輯推噓5(501)
留言6則, 6人參與, 4周前最新討論串270/394 (看更多)
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

05/24 11:17, 4周前 , 1F
大濕...
05/24 11:17, 1F

05/24 11:22, 4周前 , 2F
大師
05/24 11:22, 2F

05/24 11:23, 4周前 , 3F
我獨自刷題
05/24 11:23, 3F

05/24 12:47, 4周前 , 4F
大師
05/24 12:47, 4F

05/24 13:32, 4周前 , 5F
別卷了
05/24 13:32, 5F

05/24 15:14, 4周前 , 6F
大師
05/24 15:14, 6F
文章代碼(AID): #1cK0Q6yX (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cK0Q6yX (Marginalman)