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 ...
随机推荐
- PostgreSQL函数:查询包含时间分区字段的表,并更新dt分区为最新分区
一.需求 1.背景 提出新需求后,需要在www环境下进行验收.故需要将www环境脚本每天正常调度 但由于客户库无法连接,ods数据无法每日取,且连不上客户库任务直接报错,不会跑ods之后的任务 故需要 ...
- 【消息队列面试】15-17:高性能和高吞吐、pull和push、各种MQ的区别
十五.kafka高性能.高吞吐的原因 1.应用 日志收集(高频率.数据量大) 2.如何保证 (1)磁盘的顺序读写-pagecache关联 rabbitmq基于内存读写,而kafka基于磁盘读写,但却拥 ...
- Rust学习之旅(读书笔记):枚举 (Enum)
Rust学习之旅(读书笔记):枚举 (Enum) C 语言的枚举类型很弱,不如后来的语言,也不如之前的语言.在 C 语言里面枚举量就是一个名字,更方便的定义常量.今天读了<The Rust Pr ...
- 一键部署MySQL8+keepalived双主热备高可用
概述 本次的文章会格外的长,网上大多的配置流程已经不可使用,本篇文章可以称为保姆级教程,而且通过shell脚本大大减少了部署mysql主从,双主的工作量. 如上图,VIP地址为192.168.10.1 ...
- Python全栈工程师之从网页搭建入门到Flask全栈项目实战(6) - Flask表单的实现
1.表单介绍 1.1.表单知识回顾 常见的表单元素: 表单标签<form> action:表单提交的URL地址 method:表单请求的方式(GET/POSt) enctype:请求内容的 ...
- 过两年 JVM 可能就要被 GraalVM 替代了
大家好,我是风筝,公众号「古时的风筝」,专注于 Java技术 及周边生态. 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在里面. 今天说一说 Graal ...
- flutter系列之:移动端手势的具体使用
目录 简介 赋予widget可以点击的功能 会动的组件 可删除的组件 总结 简介 之前我们介绍了GestureDetector的定义和其提供的一些基本的方法,GestureDetector的好处就是可 ...
- Jmeter 跨线程组传参
某种情况下需要获取到上个线程组的返回值进行测试,但线程组与线程组之间是相互独立,互不影响.若要得到上个线程组的返回值,则可通过__setProperty()函数将所提取的值设置为jmeter 内置属性 ...
- 希腊字母表及latex代码
希腊字母表及latex代码 字母大写 字母小写 英文名称 latex大写代码 latex小写代码 \(\Alpha\) \(\alpha\) alpha \Alpha \alpha \(\Beta\) ...
- [机器学习] PCA (主成分分析)详解
转载于https://my.oschina.net/gujianhan/blog/225241 一.简介 PCA(Principal Components Analysis)即主成分分析,是图像处理中 ...