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 ...
随机推荐
- 关于仿照js写python算法
前言 我们学校的统一认证的登录系统,用了一套不知道哪弄来的 js加密算法 (我已经查到了,应该是出自这里 地址),有一个参数是通过 js 计算得到的,无奈我先想模拟登录就必须解决这个算法,这个说明是d ...
- MySQL进阶实战1,数据类型与三范式
一.选择优化的数据类型 MySQL支持的数据类型非常多,选择正确的数据类型对于获得高性能至关重要. 1.更小的 一般情况下,应该尽量使用较小的数据类型,更小的数据类型通常更快,因为占用更少的磁盘.内存 ...
- js-day05-对象
为什么要学习对象 没有对象时,保存网站用户信息时不方便,很难区别 对象是什么 1.对象是一种数据类型 2.无序的数据集合 对象有什么特点 1.无序的数据的集合 2.可以详细的描述某个事物' 对象使用 ...
- Go DevOps大厂运维平台开发进阶实战营
使用 Jenkinsfile 创建流水线已报名老男孩运维课,见底下评论.enkinsfile 是一个文本文件,它包含 Jenkins 流水线的定义,并被检入源代码控制仓库.Jenkinsfile 将整 ...
- python基础语法&数据类型&运算符
1.标识符 # -*- coding:utf-8 -*- # @Time :2021/1/16 10:28 # @Author :QAbujiaban # @Email :wbxztoo@163.co ...
- Kagol:2022年最值得推荐的前端开源文章
大家好,我是 Kagol,Vue DevUI 作者,从2020年开始一直专注于前端开源组件库的建设,在前端开源组件库.开源社区运营方面积累了一些经验,2020年主要的创作也是围绕前端组件库和开源两个主 ...
- [OpenCV实战]6 基于特征点匹配的视频稳像
目录 1 介绍 1.1 视频稳定的方法 1.2 使用点特征匹配的视频稳定 2 算法 2.1 帧间运动信息获取 2.1.1 合适的特征点获取 2.1.2 Lucas-Kanade光流法 2.1.3 运动 ...
- [R语言] R语言快速入门教程
本文主要是为了从零开始学习和理解R语言,简要介绍了该语言的最重要部分,以快速入门.主要参考文章: R-Tutorial R语言程序的编写需要安装R或RStudio,通常是在RStudio中键入代码.但 ...
- P5934 [清华集训2012]最小生成树
简要题意 给你一个 \(N\) 个点,\(M\) 条边的 无向连通 带权图.给定一条边 \((u,v,L)\),请问需要在原图中删除多少条边,使得将 \((u,v,L)\) 插入图后,它既可能在最小生 ...
- 在Ubuntu上安装OpenShift并使用
服务器信息 在阿里云买了个抢占式的服务器,地区为华南广州,系统为Ubuntu 20.04,8核16GB. 安装Docker 命令如下: $ apt-get update -y $ apt-get up ...