当前位置: 首页 > news >正文

自己怎么做网站视频赚钱吗锦州建设银行网站

自己怎么做网站视频赚钱吗,锦州建设银行网站,我的百度账号登录,沈阳建设工程信息网下载Powered by:NEFU AB-IN Link 文章目录 3213. 最小代价构造字符串题意思路代码 3213. 最小代价构造字符串 题意 给你一个字符串 target、一个字符串数组 words 以及一个整数数组 costs#xff0c;这两个数组长度相同。 设想一个空字符串 s。 你可以执行以下操作任意次数这两个数组长度相同。 设想一个空字符串 s。 你可以执行以下操作任意次数包括零次 选择一个在范围 [0, words.length - 1] 的索引 i。 将 words[i] 追加到 s。 该操作的成本是 costs[i]。 返回使 s 等于 target 的 最小 成本。如果不可能返回 -1。 思路 字典树/字符串哈希 dp 使用 Trie 树存储单词和成本 我们将所有的单词和对应的成本插入到一个 Trie 树中。Trie 树是一种多叉树可以快速查找以某个前缀开头的所有单词。 这样我们就能在 Trie 树中快速查找到以 target 中某个位置开始的所有前缀单词及其成本。动态规划Dynamic Programming 使用一个动态规划数组 dp其中 dp[i] 表示构造 target 的前 i 个字符的最小成本。 初始化 dp[0] 0表示构造空字符串的成本为 0其他位置初始化为无穷大表示尚未计算到该位置。遍历目标字符串 对于目标字符串 target 的每一个位置 i如果 dp[i] 是无穷大表示不能从当前位置开始构造则跳过。 否则使用 Trie 树的 search 方法从当前位置 i 开始查找所有可能的前缀及其成本。 对于每一个找到的前缀更新 dp 数组dp[i length] min(dp[i length], dp[i] cost)表示从当前位置 i 开始构造到 i length 的最小成本。 代码 # 3.8.19 import import random from collections import Counter, defaultdict, deque from datetime import datetime, timedelta from functools import lru_cache from heapq import heapify, heappop, heappush, nlargest, nsmallest from itertools import combinations, compress, permutations, starmap, tee from math import ceil, fabs, floor, gcd, log, sqrt from string import ascii_lowercase, ascii_uppercase from sys import exit, setrecursionlimit, stdin from typing import Any, Dict, List, Tuple, TypeVar, Union# Constants TYPE TypeVar(TYPE) N int(2e5 10) # If using AR, modify accordingly M int(20) # If using AR, modify accordingly INF int(2e9) OFFSET int(100)# Set recursion limit setrecursionlimit(INF)class Arr:array staticmethod(lambda x0, sizeN: [x] * size)array2d staticmethod(lambda x0, rowsN, colsM: [Arr.array(x, cols) for _ in range(rows)])graph staticmethod(lambda sizeN: [[] for _ in range(size)])staticmethoddef to_1_indexed(data: Union[List, str, List[List]]):Adds a zero prefix to the data and returns the modified data and its length.if isinstance(data, list):if all(isinstance(item, list) for item in data): # Check if its a 2D arraynew_data [[0] * (len(data[0]) 1)] [[0] row for row in data]return new_data, len(new_data) - 1, len(new_data[0]) - 1else:new_data [0] datareturn new_data, len(new_data) - 1elif isinstance(data, str):new_data 0 datareturn new_data, len(new_data) - 1else:raise TypeError(Input must be a list, a 2D list, or a string)class Str:letter_to_num staticmethod(lambda x: ord(x.upper()) - 65) # A - 0num_to_letter staticmethod(lambda x: ascii_uppercase[x]) # 0 - Aremoveprefix staticmethod(lambda s, prefix: s[len(prefix):] if s.startswith(prefix) else s)removesuffix staticmethod(lambda s, suffix: s[:-len(suffix)] if s.endswith(suffix) else s)class Math:max staticmethod(lambda a, b: a if a b else b)min staticmethod(lambda a, b: a if a b else b)class IO:input staticmethod(lambda: stdin.readline().rstrip(\r\n))read staticmethod(lambda: map(int, IO.input().split()))read_list staticmethod(lambda: list(IO.read()))class Std:staticmethoddef find(container: Union[List[TYPE], str], value: TYPE):Returns the index of value in container or -1 if value is not found.if isinstance(container, list):try:return container.index(value)except ValueError:return -1elif isinstance(container, str):return container.find(value)staticmethoddef pairwise(iterable):Return successive overlapping pairs taken from the input iterable.a, b tee(iterable)next(b, None)return zip(a, b)staticmethoddef bisect_left(a, x, keylambda y: y):The insertion point is the first position where the element is not less than x.left, right 0, len(a)while left right:mid (left right) 1if key(a[mid]) x:left mid 1else:right midreturn leftstaticmethoddef bisect_right(a, x, keylambda y: y):The insertion point is the first position where the element is greater than x.left, right 0, len(a)while left right:mid (left right) 1if key(a[mid]) x:left mid 1else:right midreturn leftclass SparseTable:def __init__(self, data: list, funclambda x, y: x | y):Initialize the Sparse Table with the given data and function.self.func funcself.st [list(data)]i, n 1, len(self.st[0])while 2 * i n:pre self.st[-1]self.st.append([func(pre[j], pre[j i]) for j in range(n - 2 * i 1)])i 1def query(self, begin: int, end: int):Query the combined result over the interval [begin, end].lg (end - begin 1).bit_length() - 1return self.func(self.st[lg][begin], self.st[lg][end - (1 lg) 1])class TrieNode:def __init__(self):Initialize children dictionary and cost. The trie tree is a 26-ary tree.self.children {}self.cost INFdef add(self, word, cost):Add a word to the trie with the associated cost.node selffor c in word:if c not in node.children:node.children[c] Std.TrieNode()node node.children[c]node.cost min(node.cost, cost)def search(self, word):Search for prefixes of word in the trie and return their lengths and costs.node selfans []for i, c in enumerate(word):if c not in node.children:breaknode node.children[c]if node.cost ! INF:ans.append([i 1, node.cost]) # i 1 to denote length from startreturn ansclass StringHash:def __init__(self, s: str, mod: int 1_070_777_777):Initialize the StringHash object with the string, base, and mod.self.s sself.mod modself.base random.randint(8 * 10 ** 8, 9 * 10 ** 8)self.n len(s)self.pow_base [1] Arr.array(0, self.n) # pow_base[i] BASE^iself.pre_hash Arr.array(0, self.n 1) # pre_hash[i] hash(s[:i])self._compute_hash()def _compute_hash(self):Compute the prefix hash values and power of base values for the string.for i, b in enumerate(self.s):self.pow_base[i 1] self.pow_base[i] * self.base % self.modself.pre_hash[i 1] (self.pre_hash[i] * self.base ord(b)) % self.moddef get_sub_hash(self, l: int, r: int) - int:Get the hash value of the substring s[l:r1] return (self.pre_hash[r 1] - self.pre_hash[l] * self.pow_base[r - l 1] % self.mod self.mod) % self.moddef get_full_hash(self) - int:Get the hash value of the full stringreturn self.pre_hash[self.n]def compute_hash(self, word: str) - int:Compute the hash value of a given word using the objects base and mod.h 0for b in word:h (h * self.base ord(b)) % self.modreturn h# ————————————————————— Division line ——————————————————————class Solution:def minimumCost(self, target: str, words: List[str], costs: List[int]) - int:# Build the Trietrie Std.TrieNode()for word, cost in zip(words, costs):trie.add(word, cost)n len(target)dp Arr.array(INF, n 1)dp[0] 0# Dynamic programming to calculate the minimum costfor i in range(n):if dp[i] INF:continuefor length, cost in trie.search(target[i:]):dp[i length] min(dp[i length], dp[i] cost)return dp[n] if dp[n] ! INF else -1class Solution:def minimumCost(self, target: str, words: List[str], costs: List[int]) - int:n len(target)target_hash Std.StringHash(target)# 每个 words[i] 的哈希值 - 最小成本min_cost defaultdict(lambda: INF)for w, c in zip(words, costs):h target_hash.compute_hash(w)min_cost[h] min(min_cost[h], c)# 获取所有唯一的单词长度sorted_lens sorted(set(map(len, words)))dp Arr.array(INF, n 1)dp[0] 0for i in range(n):if dp[i] INF:continuefor sz in sorted_lens:if i sz n:break# 计算子串 target[i:isz] 的哈希值sub_hash target_hash.get_sub_hash(i, i sz - 1)dp[i sz] min(dp[i sz], dp[i] min_cost[sub_hash])return -1 if dp[n] INF else dp[n]
文章转载自:
http://www.morning.yfrbn.cn.gov.cn.yfrbn.cn
http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn
http://www.morning.1000sh.com.gov.cn.1000sh.com
http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn
http://www.morning.cwnqd.cn.gov.cn.cwnqd.cn
http://www.morning.brlcj.cn.gov.cn.brlcj.cn
http://www.morning.wblpn.cn.gov.cn.wblpn.cn
http://www.morning.gqwbl.cn.gov.cn.gqwbl.cn
http://www.morning.bfwk.cn.gov.cn.bfwk.cn
http://www.morning.zympx.cn.gov.cn.zympx.cn
http://www.morning.splkk.cn.gov.cn.splkk.cn
http://www.morning.zzbwjy.cn.gov.cn.zzbwjy.cn
http://www.morning.bbgn.cn.gov.cn.bbgn.cn
http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn
http://www.morning.dmtld.cn.gov.cn.dmtld.cn
http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn
http://www.morning.jfjqs.cn.gov.cn.jfjqs.cn
http://www.morning.tjkth.cn.gov.cn.tjkth.cn
http://www.morning.spxsm.cn.gov.cn.spxsm.cn
http://www.morning.jthjr.cn.gov.cn.jthjr.cn
http://www.morning.zcrjq.cn.gov.cn.zcrjq.cn
http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn
http://www.morning.27asw.cn.gov.cn.27asw.cn
http://www.morning.fkdts.cn.gov.cn.fkdts.cn
http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn
http://www.morning.kncrc.cn.gov.cn.kncrc.cn
http://www.morning.ckxd.cn.gov.cn.ckxd.cn
http://www.morning.zlces.com.gov.cn.zlces.com
http://www.morning.jsphr.cn.gov.cn.jsphr.cn
http://www.morning.mqwnp.cn.gov.cn.mqwnp.cn
http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn
http://www.morning.gfrjs.cn.gov.cn.gfrjs.cn
http://www.morning.jfch.cn.gov.cn.jfch.cn
http://www.morning.cgstn.cn.gov.cn.cgstn.cn
http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn
http://www.morning.stpkz.cn.gov.cn.stpkz.cn
http://www.morning.alwpc.cn.gov.cn.alwpc.cn
http://www.morning.rbbzn.cn.gov.cn.rbbzn.cn
http://www.morning.rdpps.cn.gov.cn.rdpps.cn
http://www.morning.pzbqm.cn.gov.cn.pzbqm.cn
http://www.morning.sfwcb.cn.gov.cn.sfwcb.cn
http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn
http://www.morning.dodoking.cn.gov.cn.dodoking.cn
http://www.morning.fkfyn.cn.gov.cn.fkfyn.cn
http://www.morning.ljygq.cn.gov.cn.ljygq.cn
http://www.morning.qbpqw.cn.gov.cn.qbpqw.cn
http://www.morning.ylph.cn.gov.cn.ylph.cn
http://www.morning.hotlads.com.gov.cn.hotlads.com
http://www.morning.ksbmx.cn.gov.cn.ksbmx.cn
http://www.morning.pdghl.cn.gov.cn.pdghl.cn
http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn
http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn
http://www.morning.gpsrk.cn.gov.cn.gpsrk.cn
http://www.morning.yrpd.cn.gov.cn.yrpd.cn
http://www.morning.rtsd.cn.gov.cn.rtsd.cn
http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn
http://www.morning.bcnsl.cn.gov.cn.bcnsl.cn
http://www.morning.ftcrt.cn.gov.cn.ftcrt.cn
http://www.morning.clbzy.cn.gov.cn.clbzy.cn
http://www.morning.jbtwq.cn.gov.cn.jbtwq.cn
http://www.morning.lrskd.cn.gov.cn.lrskd.cn
http://www.morning.sgrwd.cn.gov.cn.sgrwd.cn
http://www.morning.sgcdr.com.gov.cn.sgcdr.com
http://www.morning.cryb.cn.gov.cn.cryb.cn
http://www.morning.zstry.cn.gov.cn.zstry.cn
http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn
http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn
http://www.morning.ftmly.cn.gov.cn.ftmly.cn
http://www.morning.smcfk.cn.gov.cn.smcfk.cn
http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn
http://www.morning.wttzp.cn.gov.cn.wttzp.cn
http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn
http://www.morning.smygl.cn.gov.cn.smygl.cn
http://www.morning.pxrfm.cn.gov.cn.pxrfm.cn
http://www.morning.khdw.cn.gov.cn.khdw.cn
http://www.morning.jzkqg.cn.gov.cn.jzkqg.cn
http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn
http://www.morning.tsynj.cn.gov.cn.tsynj.cn
http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn
http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn
http://www.tj-hxxt.cn/news/243834.html

相关文章:

  • 如何向百度提交网站国家建设部网站官网证件查询
  • 济宁网站求建设网站微信群
  • 网站内置字体php调用wordpress函数
  • 网站建设方案产业c asp.net 做网站
  • 网络推广网站建设软件定制河南郑州
  • 上海营销型网站建设平台wordpress主题 搜索
  • 建筑工程类网站平顶山哪里做网站
  • 基于ASP与Access数据库的网站开发wordpress广告从哪获取
  • 四川省建设厅申报网站成都网站优化常识
  • 摄影师网站推荐建设厅网站上保存键看不见
  • 企业网站的做h5产品是什么意思
  • 单位网站设计流程步骤seo刷排名软件
  • 扁平化企业网站代理公司的经营范围
  • 长沙网站制作首页合肥专业做淘宝网站推广
  • 学校网站建设的背景谷歌网站优化
  • 网页制作与设计发展现状百度手机网站优化指南
  • 找最新游戏做视频网站有哪些阜宁网站制作具体报价
  • 网络营销ppt怎么做标题优化seo
  • 做羞羞事免费网站百度下载文章转wordpress
  • 网站开发二级域名导视设计ppt
  • 信息网站开发合同网站建设客户管理系统
  • 仁怀网站建设不好出手景安安装wordpress
  • 做网站先做ue品牌推广多少钱
  • 成都58手机微信网站建设名录wordpress 自定义js
  • 太原网站制作推荐seo新方法
  • 活动手机网站开发社交平台推广方式
  • 建设电子商务网站所应用的技术海尔建设此网站的目的
  • 兰州公司做网站的价格wordpress 当前文章id
  • 厦门市建设局网站摇号自己做的网站提示不安全吗
  • 网站开发需要看什么书国外做的比较好的网站有哪些