精華區beta Marginalman 關於我們 聯絡資訊
比昨天的簡單 昨天的好難 我好爛== def maxScoreWords(self, words: List[str], letters: List[str], score: List[int]) -> int: ans = 0 letters_cnt = [letters.count(chr(i)) for i in range(ord('a'), ord('z')+1)] n = len(words) def dfs(idx, score_cur): nonlocal ans if idx == n: ans = max(score_cur, ans) return if all([ words[idx].count(c) <= letters_cnt[ord(c)-ord('a')] for c in words[idx] ]): score_add = sum([score[ord(c) - ord('a')] for c in words[idx]]) score_cur += score_add for c in words[idx]: letters_cnt[ord(c) - ord('a')] -= 1 dfs(idx+1, score_cur) score_cur -= score_add for c in words[idx]: letters_cnt[ord(c) - ord('a')] += 1 dfs(idx+1, score_cur) dfs(0, 0) return ans -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1716564028.A.8DA.html ※ 編輯: DJYOSHITAKA (125.228.146.144 臺灣), 05/24/2024 23:20:40
sustainer123: 我也感覺這題沒比昨天難多少 05/24 23:21
JIWP: 剩我不會寫hard了 05/24 23:24
sustainer123: 你是兩百天大師 05/24 23:25
Rushia: 我今天用python寫這題counter一直數的怪怪的直接換java寫 05/25 01:10