题目描述:

方法:穷举暴力

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. poj 1144 割点模板题

    题目大意: 求割点: 基本思路: tarjan算法,套板子 代码如下: #include<iostream> #include<string> #include<vect ...

  2. jdbcTemplate查询结果为对象list

    RowMapper<WmsExpensesSettleEntity> rowMapper1=new BeanPropertyRowMapper<WmsExpensesSettleEn ...

  3. 【多线程】synchronized 和ReentrantLock

    1. 锁的实现 synchronized 是 JVM 实现的,而 ReentrantLock 是 JDK 实现的. 2. 性能 新版本 Java 对 synchronized 进行了很多优化,例如自旋 ...

  4. centos7 安装PHP5.3 报错undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'

    系统:centos 7 原有PHP版本:5.6.27,5.4.45 试着安装nginx+多php版本,首先安装了5.6和5.4的版本,一帆风顺,但是在安装5.3.29版本时,出现问题了,configu ...

  5. Jetson Nano系列教程0:初识Jetson Nano

    关于Jetson Nano Developer Kit Jetson nano搭载四核Cortex-A57 MPCore 处理器,采用128 核 Maxwell™  GPU.支持JetPack SDK ...

  6. docker常见启动参数

    dockerd启动参数详解: dockerd \ --bip \ #设置docker0网段 --selinux-enabled=false \ #关闭selinux --insecure-regist ...

  7. SQL必知必会——创建和操纵表(十七)

    1.创建表 一般有两种创建表的方法: 多数DBMS都具有交互式创建和管理数据库表的工具表也可以直接用SQL语句操纵1.1.表创建基础 CREATE TABLE products( prod_id,CH ...

  8. 为什么要用getBaseContext()方法代替this?(转)

    问:this 常常引用当前的 context.但是有些时候,必须使用getBaseContext()来代替this.就是说使用this会引发错误. 如下面的例子: Spinner spinner = ...

  9. line-height继承

    父元素设置ling-height;子元素继承父元素的line-height 1.ling-height:固定像素 body{ font-size:20px; line-height: 24px; } ...

  10. 【react】---react中使用装饰器

    一.creact-react-app中使用装饰器 运行 npm run eject 可以让由create-react-app创建的项目的配置项暴露出来 此时,项目中多了一个config文件,并且各个配 ...