精華區beta Marginalman 關於我們 聯絡資訊
1255. 怎麼大家都覺得比昨天簡單 我哭了 今天這個我想好久 我一直以為是有點像疊俄羅斯方塊 方塊數量不限 想說一定有什麼很好check怎麼疊的辦法 結果一直想不到最後爆搜發現 是any set of words啊啊啊啊啊 還是爆搜 沒啥差別 我就這樣了 最笨那種 所以如果這題不限制每個word只能用一次要怎麼解 有沒有除了爆搜之外很好的擺法 這裡有tetris 大師嗎 紫姆咪>_<?? class Solution { public: int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) { unordered_map <char, int> mletter; for(char c: letters){ mletter[c]++; } vector <int> wordsc; for(string s: words){ int sc = 0; for(char c: s){ sc += score[(int)(c-'a')]; } wordsc.push_back(sc); } return counter(words, 0, mletter, wordsc, 0); } bool canpush(string& w, unordered_map<char, int> mletter){ for(char c: w){ if(mletter[c] <= 0) return false; mletter[c]--; } return true; } int counter(vector<string>& words, int idx, unordered_map<char, int> mletter,\ vector<int>& wordsc, int res ){ if(idx >= words.size()) return res; //int pt = pushtimes(words[idx], mletter); int maxres = res; cout << res << endl; maxres = max(maxres, counter(words, idx+1, mletter, wordsc, res)); if(canpush(words[idx], mletter)){ for(char c: words[idx]){ mletter[c]--; } res += wordsc[idx]; maxres = max(maxres, counter(words, idx+1, mletter, wordsc, res)); } return maxres; } }; ※ 引述《DJYOSHITAKA (franchouchouISBEST)》之銘言: : 比昨天的簡單 : 昨天的好難 : 我好爛== : ----- Sent from JPTT on my iPad -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1716581940.A.44C.html