leetcode-162周赛-1255-得分最高的单词集合
题目描述:


方法:穷举暴力
class Solution:
def maxScoreWords(self, words: List[str], letters: List[str], score: List[int]) -> int:
from collections import Counter
n = len(words)
v = lambda c: ord(c) - ord('a')
words = [Counter(v(c) for c in w) for w in words]
scores = [sum(score[k]*v for k, v in w.items()) for w in words]
avail = [0]*26
for c in letters: avail[v(c)] += 1
best = [0]
curr = [0]
def dfs(i):
if i == n:
best[0] = max(best[0], curr[0])
return
dfs(i+1)
if all(avail[k] >= v for k, v in words[i].items()):
for k, v in words[i].items(): avail[k] -= v
curr[0] += scores[i]
dfs(i+1)
curr[0] -= scores[i]
for k, v in words[i].items(): avail[k] += v
dfs(0)
return best[0]
leetcode-162周赛-1255-得分最高的单词集合的更多相关文章
- LeetCode 1255 得分最高的单词集合 Maximum Score Words Formed by Letters
地址 https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters/ 题目描述你将会得到一份单词表 words,一个字母 ...
- [LeetCode] 244. Shortest Word Distance II 最短单词距离 II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of ...
- [LeetCode] 245. Shortest Word Distance III 最短单词距离 III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as ...
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
- [LeetCode] Shortest Completing Word 最短完整的单词
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- [LeetCode] Most Common Word 最常见的单词
Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...
- [leetcode]244. Shortest Word Distance II最短单词距离(允许连环call)
Design a class which receives a list of words in the constructor, and implements a method that takes ...
- LeetCode(58): 最后一个单词的长度
Easy! 题目描述: 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. ...
随机推荐
- 转载关于struts命名空间的一则报警
今天花了点时间把struts2警告事件彻底的测试了一边,终于有点眉目了.希望能给其他人带来一点帮助.文章属于原创.并不需要转载的时候注明出处,而是希望转载的朋友一定要看明白本文内容再转载,因为我你都清 ...
- 如何用Word制作斜线表头?
如何用Word制作斜线表头?遇到这种问题,你一般是如何操作?本期企业网盘坚果云干货分享与大家分享有关斜线表头的制作方法. 斜线表头分单斜线表头和多斜线表头,下面分情况来了解相关的解决办法. 单斜线表头 ...
- jsp获取url路径的方法
如果你请求的URL是 http://localhost:8080/demo/Index.jsp request.getScheme() //输出:http request.getServerName ...
- windows 安装yaml支持和pytest支持等
打开cmd 输入pip install pyyaml #yaml文件支持 输入pip install pytest #pytest框架支持 输入pip install requests ...
- 51单片机PC程序计数器
PC是一个16位的计数器.用于存放和指示下一条要执行的指令的地址.寻址范围达64KB.PC有自动加1功能,以实现程序的顺序执行.PC没有地址,是不可寻址的,无法用指令对它进行读写.但在执行转移.调用. ...
- youlexuan父类配置
<!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> ...
- sql server教程
简单认识 SQL Server sql server教程 SQL Server 是 Microsoft 开发的一个关系数据库管理系统(RDBMS),现在是世界上最为常用的数据库: SQL Server ...
- 匹配Luhn算法:可用于检测银行卡卡号
匹配Luhn算法:可用于检测银行卡卡号 /** * http://www.cnblogs.com/JnKindle/p/5798974.html * * 匹配Luhn算法:可用于检测银行卡卡号 * * ...
- LOJ 2552 「CTSC2018」假面——DP
题目:https://loj.ac/problem/2552 70 分就是 f[i][j] 表示第 i 个人血量为 j 的概率.这部分是 O( n*Q ) 的:g[i][j][0/1] 表示询问的人中 ...
- rabbitmq集群-2
rabbitmq集群 原文地址:https://www.cnblogs.com/lion.net/p/5725474.html rabbitmq集群介绍 rabbitmq有3种模式,但集群模式是2种. ...