题意

求本质不同的子串个数(包括空串)

思路

序列自动机裸题

直接上代码

\(Code\)

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL; const int N = 2e5 + 5;
const int P = 1e9 + 7;
int n , nxt[N][30];
LL f[N];
char s[N]; inline LL dfs(int x)
{
if (f[x]) return f[x];
for(register int i = 0; i < 26; i++)
if (nxt[x][i]) f[x] = (f[x] + dfs(nxt[x][i])) % P;
return f[x] = (f[x] + 1) % P;
} int main()
{
scanf("%d" , &n);
int len;
while (n--)
{
scanf("%s" , s + 1);
len = strlen(s + 1);
memset(nxt , 0 , sizeof nxt);
memset(f , 0 , sizeof f);
for(register int i = len; i; i--)
{
for(register int j = 0; j < 26; j++) nxt[i - 1][j] = nxt[i][j];
nxt[i - 1][s[i] - 'A'] = i;
}
printf("%lld\n" , dfs(0) % P);
}
}

SP2416 DSUBSEQ - Distinct Subsequences的更多相关文章

  1. [LeetCode] Distinct Subsequences 不同的子序列

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  2. Distinct Subsequences

    https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...

  3. Leetcode Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  4. LeetCode(115) Distinct Subsequences

    题目 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequen ...

  5. [Leetcode][JAVA] Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  6. Distinct Subsequences Leetcode

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  7. 【leetcode】Distinct Subsequences(hard)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  8. 【LeetCode OJ】Distinct Subsequences

    Problem Link: http://oj.leetcode.com/problems/distinct-subsequences/ A classic problem using Dynamic ...

  9. LeetCode 笔记22 Distinct Subsequences 动态规划需要冷静

    Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of  ...

  10. leetcode 115 Distinct Subsequences ----- java

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

随机推荐

  1. linux系统部署微服务项目

    **:如果使用阿里云linux服务器 1.设置容器镜像服务 在阿里云平台搜索 "容器镜像服务" 选择"CentOS" 安装/升级Docker客户端 配置镜像加速 ...

  2. ATM购物车

    ATM项目实现思路: ATM架构设计 三层架构 core目录下的src.py(浏览器) (展示层) interface目录下的多个py文件(框架) (核心逻辑层) db目录下db_handler.py ...

  3. 强化学习调参技巧二:DDPG、TD3、SAC算法为例:

    1.训练环境如何正确编写 强化学习里的 env.reset() env.step() 就是训练环境.其编写流程如下: 1.1 初始阶段: 先写一个简化版的训练环境.把任务难度降到最低,确保一定能正常训 ...

  4. Nmap脚本

    Nmap的脚本默认存放在Nmap的安装路径的scripts文件夹下Nmap的脚本主要分为以下几类 Auth:负责处理鉴权证书(绕过鉴权)的脚本 Broadcast:在局域网内探查更多服务的开启情况,如 ...

  5. md5-有道翻译

    网站 aHR0cHMlM0EvL2ZhbnlpLnlvdWRhby5jb20v 测试发现三个值是变化的 一.第一种方法 initiator一步一步找,在t.translate中找到以下内容 这里可以看 ...

  6. kali安装拼音输入法

    前言 最近使用kali感觉没个中文输入法的很不方便,于是决定装个ibus的拼音输入法 安装方法 1.安装ibus 使用命令apt install ibus ibus-pinyin,注意使用root权限 ...

  7. (已转)Linux基础第六章 信号

    6.1 前言 本章简单描述信号.信号是Linux系统中,内核和进程通信的一种方式.如果内核希望打断进程的顺序执行,那么内核会在进程的PCB中记录信号.而当这个进程被分配到CPU,进入执行状态时,首先会 ...

  8. go语言的grpc环境安装

    本文直接用安装包的方式安装. 源码编译安装参考:https://www.cnblogs.com/abc36725612/p/14288333.html 环境 golang的docker image d ...

  9. 4、PageHelper分页查询

    1.MyBatis的分页方式: 逻辑分页与物理分页 1.逻辑分页:使用MyBatis自带的RowBounds进行分页,是一次性查询很多数据,然后再在结果中检索分页的数据.这样做弊端是需要消耗大量的内存 ...

  10. WCF 服务容器化的一些问题

    背景 目前项目当中存有 .NET Framework 和 .NET Core 两种类型的项目,但是都需要进行容器化将其分别部署在 Windows 集群和 Linux 集群当中.在 WCF 进行容器化的 ...