noip2015 d2t2子串
考点:线性DP+前缀和+滚动数组
思路:https://www.acwing.com/solution/content/3956/
代码:
for(int i=1;i<=n;i++){ f[i][0][0]=1; for(int j=1;j<=m;j++){ for(int k1=1;k1<=k;k1++){ if(a[i]==b[j]) sum[i][j][k1]=(sum[i-1][j-1][k1]+f[i-1][j-1][k1-1])%1000000007; else sum[i][j][k1]=0; f[i][j][k1]=(f[i-1][j][k1]+sum[i][j][k1])%1000000007; } } } time:O(NMK) time:O(nmk)
f[0][0] = 1; for (int i = 1; i <= n; i ++ ) for (int j = m; j; j -- ) for (int k = 1; k<=kk; k++ ) { if (a[i] == b[j]) sum[j][k] = (sum[j - 1][k] + f[j - 1][k - 1]) % mod; else sum[j][k] = 0; f[j][k] = (f[j][k] + sum[j][k]) % mod; }