[2018.10.18 T3] 玩串

本文探讨了如何根据给定的权值构造满足特定条件的字符串。通过定义字符串的权值为本质不同的好子序列数量,文章提出了一种有效的算法来生成这样的字符串,确保其长度不超过100,字符集大小不超过50。通过对空串进行操作,利用增加和翻倍两种策略,实现了字符串价值的调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

暂无链接

玩串

【问题描述】

艾奇非常喜欢玩串。
艾奇觉得,字符串什么的非常优美。她会有事没事地给一个字符串数它有多
少个好的非空子序列。
一个好的子序列,满足它是SSSSSS的形式。
比如说,abcabcabcabcabcabc就是好的,而233323332333就不是好的。
众所周知,一个字符串的子序列有222的长度次方个,而好的字符串长度一定是偶数。
而一个字符串的权值,就是本质不同的好的子序列的个数。
两个子序列本质不同,当且仅当它们之中任意一个字符所处的位置不同。
(以上大家应该都知道吧)
一天,艾奇数着数累了,她想知道对于一个权值xxx,你能否找到这样一个字符串呢?
当然,本题可能有多个满足条件的解,你只需要输出任何一个即可。
当然我不可能让你随意输出对吧,不然这题还做个球。
任何情况下,字符串的长度不能超过100100100,字符集大小不能超过505050
就这么简单。

【输入格式】

输入文件名为fkstring.infkstring.infkstring.in
一行一个整数,表示你输出的串需要包含的权值。

【输出格式】

输出文件名为fkstring.outfkstring.outfkstring.out
第一行一个数nnn,表示你输出字符串的长度。
第二行nnn个数,表示你输出的满足要求的串。

【输入样例 1】

详见fkstring1.infkstring1.infkstring1.in

【输出样例 1】

详见fkstring1.outfkstring1.outfkstring1.out

【数据范围】

TIM截图20181018190604.png

【备注】

下发的样例输出文件,只是供作参考,表示一种合法的字符串。
字符串的输出形式,你需要输出一行不超过100100100个数。每个数的大小不超过 505050。每个
数表示一个对应的字符。不同的数字代表不同的字符。

题解

我们考虑上空串,先让n+1n+1n+1,答案初始为空,价值为111,设整个串由两部分S1,S2S_1,S_2S1,S2构成,其中S1S_1S11,2,⋯ ,k1,2,\cdots,k1,2,,k,我们可以由下面两个操作更改整个串的价值:

价值加一:S1,S2→S1,k+1,k+1,S2S_1,S_2 \to S_1,k+1,k+1,S_2S1,S2S1,k+1,k+1,S2

价值乘二:S1,S2→S1,k+1,S2,k+1S_1,S_2\to S_1,k+1,S_2,k+1S1,S2S1,k+1,S2,k+1

然后就做完了。。。

代码
#include<bits/stdc++.h>
using namespace std;
deque<int>dui;
int n,tot,bit[30],top,i;
void in(){scanf("%d",&n);}
void ac()
{
	for(++n;n;n>>=1)bit[++top]=n&1;
	for(dui.push_front(++tot),i=top-1;i;--i,dui.push_back(++tot))if(bit[i]&1)dui.push_front(++tot);
	printf("%d\n",tot-1<<1);for(i=1;i<tot;++i)printf("%d ",i);for(;dui.size()>1;dui.pop_front())printf("%d ",dui.front());
}
int main(){in(),ac();}
``` from bertopic import BERTopic import numpy as np import pandas as pd from umap import UMAP from hdbscan import HDBSCAN from sklearn.feature_extraction.text import CountVectorizer from bertopic.vectorizers import ClassTfidfTransformer import re import nltk from nltk.corpus import stopwords from nltk.stem import WordNetLemmatizer from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS from nltk.tokenize import word_tokenize from wordcloud import WordCloud import matplotlib.pyplot as plt # 加载原始文本数据(仍需用于主题表示) df = pd.read_csv(&#39;tokenized_abstract.csv&#39;, encoding=&#39;utf-8&#39;) sentences = df[&#39;Tokenized_Abstract&#39;].tolist() print(&#39;文本条数: &#39;, len(sentences)) print(&#39;预览第一条: &#39;, sentences[0]) # 检查缺失值 print("缺失值数量:", df[&#39;Tokenized_Abstract&#39;].isna().sum()) # 检查非字符串类型 non_str_mask = df[&#39;Tokenized_Abstract&#39;].apply(lambda x: not isinstance(x, str)) print("非字符串样本:\n", df[non_str_mask][&#39;Tokenized_Abstract&#39;].head()) vectorizer_model = None from sentence_transformers import SentenceTransformer # 加载时间数据 df[&#39;Date&#39;] = pd.to_datetime(df[&#39;Date&#39;]) # 从Date列提取年份 years = df[&#39;Date&#39;].dt.year print(years) # Step 1 - Extract embeddings embedding_model = SentenceTransformer("C:\\Users\\18267\\.cache\\huggingface\\hub\\models--sentence-transformers--all-mpnet-base-v2\\snapshots\\9a3225965996d404b775526de6dbfe85d3368642") embeddings = np.load(&#39;clean_emb_last.npy&#39;) print(f"嵌入的形状: {embeddings.shape}") # Step 2 - Reduce dimensionality umap_model = UMAP(n_neighbors=7, n_components=10, min_dist=0.0, metric=&#39;cosine&#39;,random_state=42) # Step 3 - Cluster reduced embeddings hdbscan_model = HDBSCAN(min_samples=7, min_cluster_size=60,metric=&#39;euclidean&#39;, cluster_selection_method=&#39;eom&#39;, prediction_data=True) # Step 4 - Tokenize topics # Combine custom stop words with scikit-learn&#39;s English stop words custom_stop_words = [&#39;h2&#39;, &#39;storing&#39;, &#39;storage&#39;, &#39;include&#39;, &#39;comprise&#39;, &#39;utility&#39;, &#39;model&#39;, &#39;disclosed&#39;, &#39;embodiment&#39;, &#39;invention&#39;, &#39;prior&#39;, &#39;art&#39;, &#39;according&#39;, &#39;present&#39;, &#39;method&#39;, &#39;system&#39;, &#39;device&#39;, &#39;may&#39;, &#39;also&#39;, &#39;use&#39;, &#39;used&#39;, &#39;provide&#39;, &#39;wherein&#39;, &#39;configured&#39;, &#39;predetermined&#39;, &#39;plurality&#39;, &#39;comprising&#39;, &#39;consists&#39;, &#39;following&#39;, &#39;characterized&#39;, &#39;claim&#39;, &#39;claims&#39;, &#39;said&#39;, &#39;first&#39;, &#39;second&#39;, &#39;third&#39;, &#39;fourth&#39;, &#39;fifth&#39;, &#39;one&#39;, &#39;two&#39;, &#39;three&#39;,&#39;hydrogen&#39;] # Create combined stop words set all_stop_words = set(custom_stop_words).union(ENGLISH_STOP_WORDS) vectorizer_model = CountVectorizer(stop_words=list(all_stop_words)) # Step 5 - Create topic representation ctfidf_model = ClassTfidfTransformer() # All steps together topic_model = BERTopic( embedding_model=embedding_model, # Step 1 - Extract embeddings umap_model=umap_model, # Step 2 - Reduce dimensionality hdbscan_model=hdbscan_model, # Step 3 - Cluster reduced embeddings vectorizer_model=vectorizer_model, # Step 4 - Tokenize topics ctfidf_model=ctfidf_model, # Step 5 - Extract topic words top_n_words=50 ) # 拟合模型 topics, probs = topic_model.fit_transform(documents=sentences, # 仍需提供文档用于主题词生成 embeddings=embeddings # 注入预计算嵌入) ) # 获取主题聚类信息 topic_info = topic_model.get_topic_info() print(topic_info)```使用BERTopic的动态主题功能,传入时间戳参数,并在拟合后分析主题随时间的变化。设置时间戳 t1=2000-2010 年,t2=2011-2018 年,t3=2019-2024 年。最终,将当前阶段和前一阶段的 c-TF-IDF 平均值作为当前阶段的权重分数,取权重分数前 15 的单词作为动态主题的关键词,形成动态主题词列表。在动态主题方面,分别选取主题在每个阶段改进 c-TF-IDF 值排名前 15 的单词作为关键词绘制演化图分析主题在不同阶段的动态变化。请你提供方案实现上述操作。
最新发布
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值