代码拉取完成,页面将自动刷新
from config import Config
from quant_server_new.event_bus import EventBus
from utils.log_util import get_logger
from quant_server_new.data_feed import BacktestBarFeed
import pandas as pd
import numpy as np
import time
logger = get_logger()
# 手动创建一个DF数据
def try_pd():
# df1 = pd.DataFrame(["a", "b", "c", "d"])
# print(df1)
# # 创建二维的np数组,可以直接用np的数组的方法和属性
# df2 = pd.DataFrame([["a", "A"], ["b", "B"], ["c", "C"], ["d", "D"]])
# print(df2, df2.shape)
arr1 = np.array([["a", "A"], ["b", "B"], ["c", "C"], ["d", "D"]])
df3 = pd.DataFrame(arr1, columns=["lowercase", "uppercase"], index=["一", "二", "三", "四"])
df4 = pd.DataFrame(df3, columns=["lowercase"])
print(df4.index, df4.columns, df4.values)
def read_column(file_path, column, start=None, end=None) -> pd.Series:
read_csv = pd.read_csv(file_path)
prices = read_csv[column][-50:]
if start and not end:
return prices[start:]
if end and not start:
return prices[0:end]
if start and end:
return prices[start:end]
def try_func():
pass
def init_system():
logger.info(Config.PARENT_DIR)
file = Config.DATA_DIR+"sh000001.csv"
logger.info(file)
test_event_bus = EventBus(sample_freq=1)
bt_bar_feed = BacktestBarFeed(test_event_bus,file)
bt_bar_feed.start()
class Cat:
def __int__(self):
# self.name = name
print("cat init get called")
def __new__(cls,value):
obj = object.__new__(cls)
obj.age = value
print("cat new get called")
return obj
def test():
print(float("inf"))
class Trie:
def __init__(self):
self.children = {}
def add_word(self,word):
cur = self
for l in word:
if l not in cur.children:
cur.children[l] = Trie()
cur = cur.children[l]
def self_print(self):
for l, Tries in self.children.items():
print(l)
Tries.self_print()
from functools import cache
class Solution:
def minValidStrings(self, words, target: str) -> int:
inf = float("inf")
root = Trie()
n=len(target)
for i, word in enumerate(words):
cur = root
for c in word:
if c not in cur.children:
cur.children[c] = Trie()
cur = cur.children[c]
@cache
def dfs(i):
if i == n:
return 0
node=root
res=inf
for j in range(i,n):
if target[j] not in node.children:
break
node=node.children[target[j]]
print(target[j+1:],dfs(j+1))
res=min(res,dfs(j+1)+1)
return res
self.ans=dfs(0)
return self.ans if self.ans != inf else -1
if __name__ == "__main__":
words =["abc","aaaaa","bcdef"]
target = 'abc'
print(Solution().minValidStrings(words,target))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。