SP2416 DSUBSEQ - Distinct Subsequences
题意
求本质不同的子串个数(包括空串)
思路
序列自动机裸题
直接上代码
\(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的更多相关文章
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- Distinct Subsequences
https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...
- Leetcode Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- LeetCode(115) Distinct Subsequences
题目 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequen ...
- [Leetcode][JAVA] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- Distinct Subsequences Leetcode
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- 【leetcode】Distinct Subsequences(hard)
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- 【LeetCode OJ】Distinct Subsequences
Problem Link: http://oj.leetcode.com/problems/distinct-subsequences/ A classic problem using Dynamic ...
- LeetCode 笔记22 Distinct Subsequences 动态规划需要冷静
Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of ...
- 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 ...
随机推荐
- orcl substr函数与java substring 的不同
前天事情急改一个存储过程时遇到了substr方法时,一直用好,然后用其他方法跳过去了,今天有时间回头来验证 才发现和java太不一样了! select substr('为中华之崛起而读书',2,4) ...
- Springboot 整合 SpringCache 使用 Redis 作为缓存
一直以来对缓存都是一知半解,从没有正经的接触并使用一次,今天腾出时间研究一下缓存技术,开发环境为OpenJDK17与SpringBoot2.7.5 SpringCache基础概念 接口介绍 首先看看S ...
- 【每日一题】【与运算判断奇偶】【list的重载前后插入】2021年11月25日-103. 二叉树的锯齿形层序遍历
给定一个二叉树,返回其节点值的锯齿形层序遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). 例如:给定二叉树 [3,9,20,null,null,15,7], 来源:力扣 ...
- RGB以及RGBA
字母含义及取值 R:红色.0~255 整数 G:绿色.0~255 整数 B:蓝色.0~255 整数 A:透明度.0~1.整数或者小数 RGB和RGBA的关系 项目遇见一个需求,后台返回所占比例,前端根 ...
- Navicat破解教程
一.注意: 软件适用于WIN7/8/10/11: 安装全程断网: 下载.解压和安装都应该在英文路径下进行: 解压安装前关闭所有杀毒软件,WIN10/11系统需关闭Windows Defender的实时 ...
- Jmeter 之 switch 控制器
switch 控制器作用: switch 控制器起到了分流作用,具体应用在并发时,一部分用户执行某个场景,一部分用户执行另外一种场景,就像吞吐量控制器进行分流操作 switch 控制器字段介绍: 实例 ...
- 动态更改Spring定时任务Cron表达式的优雅方案
"Most of you are familiar with the virtues of a programmer. There are three, of course: lazines ...
- JavaScript:是一种什么样的编程语言?
有关JavaScript的发展历程,百度百科上已经说得很清楚了,这里不赘述,只是想谈一下我刚刚接触JS的一些感触. 作为后端java开发者,初次学习JS的时候,真的觉得JS非常的不严谨,很混乱.由于它 ...
- Redis数据结构与对象
参考<Redis设计与实现> 系列文章目录和关于我 一丶简单动态字符串 当redis需要的不仅仅是一个字符串字面量,而是一个可以被修改的字符串值时,就会使用SDS(simple dynam ...
- XCTF分站赛ACTF——Crypto
impossible RSA: 没啥好说的,跟我之前文章有道题类似,虽然如此还是花费了很长时间,原因令人落泪,把q = inverse(e,p)的数学式写成了eq mod p导致数学式推导及其困难(能 ...