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 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. ...
随机推荐
- .net 开源项目地址
https://github.com/dotnet/corefx 这个是.net core的 开源项目地址 https://github.com/aspnet 这个下面是asp.net core 框架 ...
- AcWing 207. 球形空间产生器 (高斯消元)打卡
有一个球形空间产生器能够在n维空间中产生一个坚硬的球体. 现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁这个球形空间产生器. ...
- ANSI 标准C 还定义了如下几个宏
ANSI 标准C 还定义了如下几个宏:_LINE_ 表示正在编译的文件的行号_FILE_ 表示正在编译的文件的名字预处理名称意义#define 宏定义#undef 撤销已定义过的宏名#include ...
- *.tar 用 tar –xvf 解压 *.gz 用 gzip -d或者gunzip 解压 *.tar.gz和*.tgz 用 tar –xzf 解压 *.bz2 用 bzip2 -d或者用bunzip2 解压 、*.tar.bz2用tar –xjf 解压
解压: 1.*.tar 用 tar –xvf 解压, --skip-old-files跳过已经存在的文件,压缩用tar -cvf 2.*.bz2 用 bzip2 -d或者用bunzip2 解压 3.* ...
- (4)C++ 复合类型-指针
篇幅长从 https://www.cnblogs.com/buchizaodian/p/11511256.html 提取出来 七.指针和自由存储空间 1.寻址运算符 * #include<io ...
- Data URL scheme 笔记
0x01起因 今天做CTF的时候,发现一堆数据,大概是这样的 data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAIUAAACFCAYAAAB12js8AAA ...
- Hello cnblogs!
console.log('Hello cnblogs')!
- upc组队赛2 Hakase and Nano【思维博弈】
Hakase and Nano 题目描述 Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). ...
- WinDows应急响应基础
文件排查 开机启动有无异常文件 msconfig 敏感的文件路径 %WINDIR% %WINDIR%\SYSTEM32\ %TEMP% %LOCALAPPDATA% %APPDATA% 用户目录 新建 ...
- 爬虫(三)—— BeautifulSoup模块获取元素
目录 BeautifulSoup 一.BeautifulSoup简介 二.安装模块 三.解析器 四.Beautiful Soup的使用 五.查找元素 1.遍历文档树 2.搜索文档树 Beautiful ...