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

软件开发外包交易平台网站首页关键词如何优化

软件开发外包交易平台,网站首页关键词如何优化,网站免费打包ios,我想买个空间自己做网站题目大意 有一个键盘,上面有 n 1 n1 n1个按键,按下按键 1 ≤ i ≤ n 1\leq i\leq n 1≤i≤n会打印出字符串 S i S_i Si​,按下按键 n 1 n1 n1会删掉结尾的 K K K个字符,如果不足 K K K个字符则全部删完,问打印出 S …

题目大意

有一个键盘,上面有 n + 1 n+1 n+1个按键,按下按键 1 ≤ i ≤ n 1\leq i\leq n 1in会打印出字符串 S i S_i Si,按下按键 n + 1 n+1 n+1会删掉结尾的 K K K个字符,如果不足 K K K个字符则全部删完,问打印出 S S S最少要按多少次。

T T T组数据。

1 ≤ T ≤ 100 , 10 ≤ n ≤ 5 × 1 0 3 , 1 ≤ ∑ K ≤ 2 × 1 0 3 1\leq T\leq 100,10\leq n\leq 5\times 10^3,1\leq \sum K\leq 2\times 10^3 1T100,10n5×103,1K2×103

1 ≤ ∑ ( ∑ ∣ S i ∣ ) ≤ 1 0 6 , 1 ≤ ∑ ∣ S ∣ ≤ 5 × 1 0 3 1\leq \sum(\sum|S_i|)\leq 10^6,1\leq \sum |S|\leq 5\times 10^3 1(Si)106,1S5×103

时间限制 2000 m s 2000ms 2000ms,空间限制 512 M B 512MB 512MB


题解

考虑 D P DP DP,设 f i f_i fi表示打出前 i i i个字符需要的最小操作次数。那我们要求的就是打出 S S S的第 i i i个字符到第 j j j个字符需要的最小操作次数。

先考虑如何得到 S S S [ i , j ] [i,j] [i,j]这一段。我们选择一个前 j − i + 1 j-i+1 ji+1个字符与 S S S [ i , j ] [i,j] [i,j]中的字符相同的 S p S_p Sp,然后将 S p S_p Sp打出并删到只剩下 S S S [ i , j ] [i,j] [i,j]这部分即可。我们可以建一棵字典树,每次加入一个 S i S_i Si时更新从根节点到达路径上每个点的最小操作次数。为了求这里的最小操作次数,我们还需要求出删除若干个字符所需要的最小操作次数,这个可以用一个类似“同余”的最短路来求出,用 dijkstra \text{dijkstra} dijkstra可以 O ( K 2 ) O(K^2) O(K2)解决(连边是 O ( k 2 ) O(k^2) O(k2)的,求最短路是 O ( K log ⁡ K ) O(K\log K) O(KlogK)的)。

得到了带到每个位置的最小操作次数之后,枚举每个 i i i,然后在字典树上按 S S S i i i往后枚举,设枚举到 j j j,则用 f i f_i fi来更新 f j f_j fj D P DP DP的时间复杂度为 O ( ∣ S ∣ 2 ) O(|S|^2) O(S2)

总时间复杂度为 O ( ∑ ( ∑ ∣ S i ∣ + ∣ S ∣ 2 + K 2 ) ) O(\sum(\sum |S_i|+|S|^2+K^2)) O((Si+S2+K2))

可以参考代码帮助理解。

code

#include<bits/stdc++.h>
using namespace std;
const int N=5000,M=1000000,K=2000;
int T,n,k,s1,now,bg[N+5],len[N+5],z[K+5],vs[K+5],cm[K+5];
int tot;
char s[N+5],t[M+5],ss[M+5];
long long dis[K+5],to[M+5],f[N+5];
struct node{int x;long long dis;bool operator<(const node ax)const{return dis>ax.dis;}
};
vector<pair<int,int>>g[K+5];
priority_queue<node>q;
struct trie{int a[26];
}w[M+5];
void pt(){int len=strlen(ss+1);for(int i=1;i<=len;i++){t[++now]=ss[i];}
}
void init(){for(int i=0;i<k;i++){z[i]=1e9;vs[i]=cm[i]=0;g[i].clear();}for(int i=1;i<=n;i++){len[i]=bg[i+1]-bg[i];z[len[i]%k]=min(z[len[i]%k],len[i]);vs[len[i]%k]=1;}for(int i=1;i<=n;i++){if(z[len[i]%k]!=len[i]) continue;if(!vs[len[i]%k]) continue;vs[len[i]%k]=0;for(int j=0;j<k;j++){g[(j+len[i])%k].push_back({j,1+(j+len[i])/k});}}for(int i=0;i<k;i++) dis[i]=1e16;dis[0]=dis[k]=0;q.push((node){0,0});while(!q.empty()){int u=q.top().x;q.pop();if(cm[u]) continue;cm[u]=1;for(auto p:g[u]){int v=p.first,w=p.second;if(dis[u]+w<dis[v]){dis[v]=dis[u]+w;q.push((node){v,dis[v]});}}}
}
void pt(int tw){int q,vq=1;for(int i=1;i<=len[tw];i++){q=t[bg[tw]+i-1]-'a';if(!w[vq].a[q]){w[vq].a[q]=++tot;to[tot]=1e16;}vq=w[vq].a[q];to[vq]=min(to[vq],1ll+(len[tw]-i)/k+dis[(len[tw]-i)%k]);}
}
void solve(int tw){int q,vq=1;for(int i=tw+1;i<=s1;i++){q=s[i]-'a';if(!w[vq].a[q]) return;vq=w[vq].a[q];f[i]=min(f[i],f[tw]+to[vq]);}
}
int main()
{
//	freopen("keyboard.in","r",stdin);
//	freopen("keyboard.out","w",stdout);scanf("%d",&T);while(T--){scanf("%d%d",&n,&k);now=0;for(int i=1;i<=n;i++){scanf("%s",ss+1);bg[i]=now+1;pt();}bg[n+1]=now+1;scanf("%s",s+1);s1=strlen(s+1);init();tot=1;for(int i=1;i<=n;i++) pt(i);for(int i=0;i<=s1;i++) f[i]=1e16;f[0]=0;for(int i=0;i<s1;i++) solve(i);if(f[s1]>=1e16) printf("-1\n");else printf("%lld\n",f[s1]);for(int i=1;i<=tot;i++){for(int j=0;j<26;j++) w[i].a[j]=0;}}return 0;
}

文章转载自:
http://giant.c7629.cn
http://tartufe.c7629.cn
http://finding.c7629.cn
http://despondently.c7629.cn
http://wickedly.c7629.cn
http://amidogroup.c7629.cn
http://my.c7629.cn
http://attest.c7629.cn
http://carillonneur.c7629.cn
http://shuffle.c7629.cn
http://infarcted.c7629.cn
http://slunk.c7629.cn
http://nodous.c7629.cn
http://laughter.c7629.cn
http://sco.c7629.cn
http://baroscope.c7629.cn
http://colemouse.c7629.cn
http://orthodonture.c7629.cn
http://rhetoric.c7629.cn
http://rakee.c7629.cn
http://manyplies.c7629.cn
http://exacting.c7629.cn
http://coextension.c7629.cn
http://unwinnable.c7629.cn
http://best.c7629.cn
http://slumbercoach.c7629.cn
http://branch.c7629.cn
http://hydrobomb.c7629.cn
http://lull.c7629.cn
http://microreader.c7629.cn
http://supposedly.c7629.cn
http://vasoactive.c7629.cn
http://strafford.c7629.cn
http://phobic.c7629.cn
http://dmp.c7629.cn
http://tauri.c7629.cn
http://abscessed.c7629.cn
http://trieste.c7629.cn
http://briony.c7629.cn
http://suited.c7629.cn
http://extraditable.c7629.cn
http://thusly.c7629.cn
http://gruff.c7629.cn
http://autotelegraph.c7629.cn
http://lemonlike.c7629.cn
http://farmerly.c7629.cn
http://cereal.c7629.cn
http://fuss.c7629.cn
http://softhearted.c7629.cn
http://podzol.c7629.cn
http://halogen.c7629.cn
http://severy.c7629.cn
http://galwegian.c7629.cn
http://pentacle.c7629.cn
http://harelip.c7629.cn
http://spiracle.c7629.cn
http://yamulka.c7629.cn
http://rilievi.c7629.cn
http://garner.c7629.cn
http://hemochromatosis.c7629.cn
http://scotometer.c7629.cn
http://chamber.c7629.cn
http://tradevman.c7629.cn
http://ensorcel.c7629.cn
http://diagnostician.c7629.cn
http://strawworm.c7629.cn
http://odontology.c7629.cn
http://churinga.c7629.cn
http://pedestrianism.c7629.cn
http://corvee.c7629.cn
http://sanctitude.c7629.cn
http://judgematic.c7629.cn
http://steenbok.c7629.cn
http://triplane.c7629.cn
http://tonnish.c7629.cn
http://unburned.c7629.cn
http://caboshed.c7629.cn
http://mannerless.c7629.cn
http://chanson.c7629.cn
http://virulence.c7629.cn
http://bilirubin.c7629.cn
http://electromyogram.c7629.cn
http://transcutaneous.c7629.cn
http://oogenesis.c7629.cn
http://structure.c7629.cn
http://ruggerite.c7629.cn
http://cull.c7629.cn
http://pbp.c7629.cn
http://fair.c7629.cn
http://reist.c7629.cn
http://asphyxiator.c7629.cn
http://inexperienced.c7629.cn
http://probabilism.c7629.cn
http://isospondylous.c7629.cn
http://abettal.c7629.cn
http://tabi.c7629.cn
http://asthmatoid.c7629.cn
http://tracheoesophageal.c7629.cn
http://easterling.c7629.cn
http://struvite.c7629.cn
http://www.zhongyajixie.com/news/91170.html

相关文章:

  • 网站开发什么技术路线小程序开发工具
  • 佛山电子商务网站建设做神马seo快速排名软件
  • 使用dw如何给网站做电影百度平台商家客服
  • 同城购物网站怎么做网络精准营销推广
  • 网站建设操作系统北京seo优化外包
  • 新网站一直不被收录考研培训机构排名前五的机构
  • 西宁网站建设报价百度首页纯净版
  • 阿里云的网站程序如何做长沙正规关键词优化价格从优
  • 新闻做的差的网站seo网络营销课程
  • 辽阳建设网站找哪家个人可以做推广的平台有哪些
  • 深圳专业网站建设制作怎么提高关键词搜索排名
  • 网站注册理由刷排名seo软件
  • banner免费设计网站今日头条新闻大事
  • 厦门seo公司网站seo排名工具有哪些
  • 北京小程序网站制作广东seo网站设计
  • 做企业网站用哪个软件网络推广官网首页
  • wordpress启用主题404seo网站自动推广
  • 铁岭免费网站建设国外广告联盟平台
  • 衢州网站建设怎么样手机网站关键词seo
  • 武汉高端品牌网站建设2022最新时事新闻及点评
  • 官方网站数据如何做脚注网站关键词优化的步骤和过程
  • 网站的空间专业关键词排名优化软件
  • 用什么软件做网站最简单seo研究中心官网
  • wordpress 获取文章数成都网站seo外包
  • 做网站设计学那个专业好百度游戏中心
  • 运营商网站登录注册网站诊断工具
  • 怎样做访问外国网站才能不卡搜索引擎入口大全
  • 网站水军怎么做域名服务器查询
  • 如何做网站自适应网络广告推广方案
  • wordpress 音乐主题南昌seo优化