标签:inf target int show def new git while template
f[i][j][k]表示a数组前i个值 b数组前j个值 c数组前k个值中的本质不同的公共字串有多少个
N3 每次都重新计算
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define rg register 4 const int N=100+5,inf=0x3f3f3f3f; 5 int n=0,la,lb,lc; 6 char a[N],b[N],c[N]; 7 long long las[4][‘z‘+5],f[N][N][N]; 8 9 template<class t>void rd(t &x) 10 { 11 x=0;int w=0;char ch=0; 12 while(!isdigit(ch)) w|=ch==‘-‘,ch=getchar(); 13 while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); 14 x=w?-x:x; 15 } 16 17 18 int main() 19 { 20 // freopen("in.txt","r",stdin); 21 scanf("%s%s%s",a,b,c); 22 la=strlen(a),lb=strlen(b),lc=strlen(c); 23 for(rg int i=0;i<la;++i) 24 { 25 las[1][a[i]]=i+1;memset(las[2],0,sizeof(las[2])); 26 for(rg int j=0;j<lb;++j) 27 { 28 las[2][b[j]]=j+1;memset(las[3],0,sizeof(las[3])); 29 for(rg int k=0;k<lc;++k) 30 { 31 las[3][c[k]]=k+1; 32 for(rg int x=‘a‘;x<=‘z‘;++x) 33 { 34 int aa=las[1][x],bb=las[2][x],cc=las[3][x]; 35 if(!aa||!bb||!cc) continue; 36 f[i+1][j+1][k+1]+=f[aa-1][bb-1][cc-1]+1; 37 } 38 } 39 } 40 } 41 printf("%lld",f[la][lb][lc]); 42 return 0; 43 }
【luogu3856】【TJOI2008】公共子串 [动态规划]
标签:inf target int show def new git while template
原文地址:https://www.cnblogs.com/lxyyyy/p/10805766.html