题目描述:

方法:穷举暴力

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-得分最高的单词集合的更多相关文章

  1. LeetCode 1255 得分最高的单词集合 Maximum Score Words Formed by Letters

    地址 https://leetcode-cn.com/problems/maximum-score-words-formed-by-letters/ 题目描述你将会得到一份单词表 words,一个字母 ...

  2. [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 ...

  3. [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 ...

  4. [LeetCode] Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  5. [LeetCode] Stickers to Spell Word 贴片拼单词

    We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...

  6. [LeetCode] Shortest Completing Word 最短完整的单词

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

  7. [LeetCode] Most Common Word 最常见的单词

    Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...

  8. [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 ...

  9. LeetCode(58): 最后一个单词的长度

    Easy! 题目描述: 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. ...

随机推荐

  1. 浅谈JavaScript原型图与内存模型

    js原型详解 1.内存模型: 1.原型是js中非常特殊一个对象,当一个函数(Person)创建之后,会随之就产生一个原型对象 2. 当通过这个函数的构造函数创建了一个具体的对象(p1)之后,在这个具体 ...

  2. atomic 原子操作的类

    import java.util.concurrent.atomic.AtomicInteger; /** * 原子操作的类 atomic */ public class VolatileDemo { ...

  3. Jetson Nano系列教程1:烧写系统镜像

    下载镜像 NVIDIA官方为Jetson Nano Developer Kit (后面统称为Jetson Nano了)提供了SD卡版本的系统镜像,并且根据JetPack版本不断得在更新.所以你可以直接 ...

  4. 使用vue完成一个分页效果

    基于 element-ui 分页组件实现分页效果 效果如下: 使用说明: 0.首先在头部引入需要的外部文件 1.从element官方网页中复制想要的组件代码直接放入body中 2.编写逻辑代码 3.完 ...

  5. NetHogs——Linux下按进程实时统计网络带宽利用率

    Debian/Ubuntu下安装很简单,执行:apt-get install nethogs 就可以安装. CentOS/RHEL下建议先安装上EPEL,再执行:yum install libpcap ...

  6. 【Tomcat】2.配置Tomcat服务器端口和HTTPS

    1.修改XML配置文件 找到Tomcat安装目录下的conf文件夹,打开server.xml文件(可以用笔记本打开) 其中有几行代码如下 <Server port="8005" ...

  7. Java IO Demo

    //FileReader FileWriter 读写英文    public void FileReaderAndWriter1() throws Exception { File filePath ...

  8. http中请求协议 GET和POST两种基本请求方法的区别

    GET和POST是什么?HTTP协议中的两种发送请求的方法. HTTP是什么?HTTP是基于TCP/IP的关于数据如何在万维网中如何通信的协议. HTTP的底层是TCP/IP.所以GET和POST的底 ...

  9. HTML5: 目录

    ylbtech-HTML5: 目录 1.返回顶部 1. http://www.runoob.com/html/html5-intro.html 2. http://www.w3school.com.c ...

  10. JS-模拟printf

    function printf(){ var args = [].slice.call(arguments), fmt = args.shift(), args_index = 0; ///%(填充的 ...