【Codeforces176D】Hyper String
来源:互联网 发布:录屏软件 编辑:程序博客网 时间:2024/06/07 02:29
定义
考虑如何转移:
考虑这样几个数组。
然后转移显然可以变为
#include <bits/stdc++.h>#define gc getchar()#define N 2009#define M 1002009using namespace std;int n,len[N],m,pos[N],now[26],last[M][26],id[N],go[N][26],L,Ans;int dp[M][2],sum[N];char a[M],s[N];int read(){ int x=1; char ch; while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1; int s=ch-'0'; while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0'; return s*x;}int main(){ n=read(); for (int i=1;i<=n;i++) { memset(now,0,sizeof(now)); scanf("%s",a+1); len[i]=strlen(a+1); pos[i+1]=pos[i]+len[i]+1; for (int j=len[i];j>=0;j--) { for (int k=0;k<26;k++) last[pos[i]+j][k]=now[k]; if (j) now[a[j]-'a']=j; } } m=read(); for (int i=1;i<=m;i++) { id[i]=read(); sum[i]=sum[i-1]+len[id[i]]; } scanf("%s",s+1); L=strlen(s+1); memset(now,0,sizeof(now)); for (int i=m;i;i--) { for (int k=0;k<26;k++) go[i][k]=now[k]; for (int k=0;k<26;k++) if (last[pos[id[i]]][k]) now[k]=i; } dp[0][0]=1,dp[0][1]=0; for (int i=1;i<=L;i++) { for (int j=Ans;j>=0;j--) { int ID=0,POS=0,c=s[i]-'a'; if (last[pos[id[dp[j][0]]]+dp[j][1]][c]) ID=dp[j][0],POS=last[pos[id[dp[j][0]]]+dp[j][1]][c]; else ID=go[dp[j][0]][c],POS=last[pos[id[ID]]][c]; if (ID&&(dp[j+1][0]==0||sum[ID-1]+POS<sum[dp[j+1][0]-1]+dp[j+1][1])) dp[j+1][0]=ID,dp[j+1][1]=POS; } if (dp[Ans+1][0]) Ans++; } printf("%d\n",Ans); return 0;}
阅读全文
0 0
- 【Codeforces176D】Hyper String
- codeforces176D——Hyper String
- Hyper
- Hyper-V
- 在Hyper
- Hyper Thread
- Hyper 源码分析-----创建hyper daemon
- Hyper-Threading Technology
- Hyper-V 初探
- 什么是Hyper Memory
- Hyper-V,虚拟多元化
- Hyper-V的网络资源
- Hyper-V 性能Tips
- 初试Hyper-V
- Hyper-V:环境篇
- Hyper-V:安装1
- Hyper-V:安装2
- 如何安装Hyper-V
- vue 分页
- LinuxStudyNote(24)-Linux常用命令(4)-文件搜索命令(1)find文件搜索命令
- syn flood攻击防范
- 让iPhone自惭形秽?关于新品三星Galaxy S8\/S8+,最全汇总看这里!
- 新版 iPhone7 发布!最好别让女朋友看到,山寨机已经出现
- 【Codeforces176D】Hyper String
- 美国101岁亿万富豪洛克菲勒去世;乐视汽车宣布张海亮接任全球CEO;小米员工买房半价没产权…
- Frequent Subsets Problem(北京网赛)
- 课堂练习2
- SetCommMask WaitCommMask
- IntelliJ IDEA和我的重构之旅(一)
- 盘点那些不为人知却堪称神器的8款系统管理软件
- 重磅!!!大佬圈架;刘强东微博怒怼马云,柳传志,雷军入局;李国庆补刀!
- 定了!10月起取消手机长途漫游费,背后深意是……