zoukankan      html  css  js  c++  java
  • 【luogu3856】【TJOI2008】公共子串 [动态规划]

    [TJOI2008]公共子串

    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 } 
  • 相关阅读:
    Blender基础操作
    反汇编及linux下edb的下载
    混淆矩阵(confusion_matrix)含义
    Python大数据第三次的作业
    Python的DataFrame基础使用
    Python数据标准化
    爬虫之xpath
    luffy项目上线
    爬虫之selenium
    celery
  • 原文地址:https://www.cnblogs.com/lxyyyy/p/10805766.html
Copyright © 2011-2022 走看看