当前位置:网站首页>Find the number of common subsequences of K strings
Find the number of common subsequences of K strings
2022-06-10 12:56:00 【sophilex】
Carelessness :
Find the number of common substrings of three strings
Ideas :
First, the sequence automata is used to find the next Array .
void init(char* s,ll mas[][30])
{
ll len=strlen(s+1);
for(int i=len;i;--i)
{
for(int j=0;j<26;++j) mas[i-1][j]=mas[i][j];
mas[i-1][s[i]-'a']=i;
}
}hypothesis dp【i】【j】【k】 Express a Serial number i After characters ,b Serial number j After characters ,c Serial number k Number of common substrings after characters ,
Then enumerate the number of substrings starting with each character , Recursion is enough .
Because the same character is also the same substring , therefore
if(x&&y&&z) dp[x][y][z]++;
code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=110;
char a[N],b[N],c[N];
ll nea[N][30],neb[N][30],nec[N][30];
void init(char* s,ll mas[][30])
{
ll len=strlen(s+1);
for(int i=len;i;--i)
{
for(int j=0;j<26;++j) mas[i-1][j]=mas[i][j];
mas[i-1][s[i]-'a']=i;
}
}
ll dp[N][N][N];
ll dfs(ll x,ll y,ll z)
{
if(dp[x][y][z]) return dp[x][y][z];
for(int i=0;i<26;++i)
{
if(nea[x][i]&&neb[y][i]&&nec[z][i])
{
dp[x][y][z]+=dfs(nea[x][i],neb[y][i],nec[z][i]);
}
}
if(x&&y&&z) dp[x][y][z]++;
return dp[x][y][z];
}
int main()
{
cin>>(a+1);cin>>(b+1);cin>>(c+1);
init(a,nea);init(b,neb);init(c,nec);
cout<<dfs(0,0,0)<<endl;
return 0;
} The same is true for multiple strings .
in addition , Using sequential automata to judge whether it is a substring :
Just cover the board directly
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e6+1000;
ll n;
char s[N];char ss[N];
ll ne[N][30];
void init()
{
ll len=strlen(s+1);
for(int i=len;i;--i)
{
for(int j=0;j<26;++j) ne[i-1][j]=ne[i][j];
ne[i-1][s[i]-'a']=i;
}
}
void solve()
{
cin>>(ss+1);
ll p=0;
for(int i=1;i<=strlen(ss+1);++i)
{
p=ne[p][ss[i]-'a'];
if(!p)
{
cout<<"No"<<endl;
return;
}
}
cout<<"Yes"<<endl;
}
int main()
{
cin>>(s+1);
cin>>n;
init();
while(n--)
{
solve();
}
return 0;
}Water is healthier ~
边栏推荐
- TIDB 初級課程體驗 8 (集群的管理維護, 添加一個TIKV節點)
- 已拿offer,进阶学习
- Tidb Primary course experience 8 (Management Maintenance of Clusters, add a tikv Node)
- Recommended learning materials for Altium Designer
- Altium Allegro PADS到底该选哪个EDA设计软件
- The Japanese version of arXiv is a cool batch: only 37 papers have been received after more than 2 months
- Vdo-slam source code reading notes [2] local optimization and global optimization
- TIDB 初级课程体验 8 (集群的管理维护, 添加一个TIKV节点)
- Add line number field to SQL query results - sqlserver
- Stereo Vision-based Semantic 3D Object and Ego-motion Tracking for Autonomous Driving 论文阅读
猜你喜欢

Oceanbase, phase II of the document promotion plan, invites you to jointly build documents

(11) Const decorated member function
![VDO-SLAM源码阅读笔记[1] Track()中动态obj部分](/img/18/7260d5b8dba4dcdb64d7f299198ad0.png)
VDO-SLAM源码阅读笔记[1] Track()中动态obj部分

KITTI 相关信息汇总

The ability to register user names and passwords with the database

Shadergraph - Crystal

Automatic Mapping of Tailored Landmark Representations for Automated Driving and Map Learning 论文阅读

Software project management 6.10 Cost budget

蚂蚁金服杨军:蚂蚁数据分析平台的演进及数据分析方法的应用

(10) Notes on null pointer accessing member function and this pointer
随机推荐
[solved] vagrant up solution to slow download box
MYSQL 主库操作大表DDL ,从库崩溃与系统参数错误设置
Software project management 6.10 Cost budget
Tidb Primary course experience 8 (Management Maintenance of Clusters, add a tikv Node)
Practical cases, in-depth analysis
PCB learning notes (2) -3d packaging related
JS converts timestamp to normal time format
日本版arXiv凉得一批:2个多月了,才收到37篇论文
百度程序员删库被判9个月,手机号一键解绑功能发布,推特再向马斯克妥协,今日更多大新闻在此...
Summary of Kitti related information
Alibaba cloud ECS server builds MySQL database
Stm32f407 clock tree and system clock learning notes
今天,一对情侣拿下香港最大电商IPO
Asynchronous export of Excel
Can chip learning of max3051
JS array to JSON, JSON to array. Array to comma separated string, string to array
If the files and graphics are lost, it means that you don't need the office developed by yourself
Automatic Mapping of Tailored Landmark Representations for Automated Driving and Map Learning 论文阅读
Creating basic stacks and queues in C language
Case sharing and implementation introduction of SAP field service management and wechat integration