题意

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

思路

序列自动机裸题

直接上代码

\(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. uni-ajax使用示例

    官网 基于 Promise 的轻量级 uni-app 网络请求库 uni-ajax官网:https://uniajax.ponjs.com 安装 插件市场 在 插件市场 右上角选择 使用 HBuild ...

  2. [信息抽取]基于ERNIE3.0的多对多信息抽取算法:属性关系抽取

    [信息抽取]基于ERNIE3.0的多对多信息抽取算法:属性关系抽取 实体关系,实体属性抽取是信息抽取的关键任务:实体关系抽取是指从一段文本中抽取关系三元组,实体属性抽取是指从一段文本中抽取属性三元组: ...

  3. Burpsuite2022.1详细图文安装教程(含工具链接)

    ​ 应用概述: Burp Suite 是用于攻击web 应用程序的集成平台,包含了许多工具.Burp Suite为这些工具设计了许多接口,以加快攻击应用程序的过程.所有工具都共享一个请求,并能处理对应 ...

  4. 虚拟网络VLAN

    一.VLAN划分基础 1.VLAN概念 VLAN叫做虚拟局域网,逻辑上将网络划分 2.VLAN的分类 静态vlan:基于端口划分静态VLAN 动态vlan:基于MAC地址划分动态VLAN 3.VLAN ...

  5. .NET周报【12月第1期 2022-12-08】

    国内文章 CAP 7.0 版本发布通告 - 支持延迟消息,性能炸了? https://www.cnblogs.com/savorboard/p/cap-7-0.html) 今天,我们很高兴宣布 CAP ...

  6. 《HTTP权威指南》 – 11.验证码和新鲜度

    服务器应当告知客户端能够将内容缓存多长时间,在这个时间内就是新鲜的.服务器可以用这两个首部之一来提供信息: Expires(过期) Cache - Control(缓存控制) Expires首部 规定 ...

  7. TCP协议三握四挥、socket模块

    目录 传输层之TCP与UDP协议 应用层 socket模块 socket代码简介 代码优化 半连接池的概念 传输层之TCP与UDP协议 用于应用程序之间的通信 TCP与UDP都是用来规定通信方式的 ​ ...

  8. if-else 的优美写法

    前言‍♂️ 相信大家或多或少都接触过拥有庞大 if else 的项目代码吧,多重嵌套的 if else 在维护的时候真的让人很恼火,有时候一个 bug 排查下来,严重感觉身体被掏空. 本文并未有消灭或 ...

  9. 基于ERNIELayout&pdfplumber-UIE的多方案学术论文信息抽取

    本项目链接:https://aistudio.baidu.com/aistudio/projectdetail/5196032?contributionType=1 基于ERNIELayout& ...

  10. js获取天气插件

    SDK介绍 根据指定入参,传入三个 select 的 id值 及 回调函数,每次选项变更都会拿到对应地区最新天气数据. 必须是三个 Select 标签 有记住选项功能,避免重复相关逻辑. 1.依赖源码 ...