[leetcode] 115. Distinct Subsequences

MATLAB实战:64QAM通信系统仿真全流程解析(附误码率优化技巧) 本文提供了一份完整的64QAM通信系统MATLAB仿真实践指南。从系统架构设计、发射端格雷码映射与脉冲成形,到信道建模、接收端同步与均衡,详细解析了全链路实现流程。文章重点分享了误码率曲线与理论值偏差的排查清单和深度优化技巧,帮助工程师构建工业级精度的仿真模型,解决高阶调制系统仿真的核心难题。 阅读详情

Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of S which equals T.

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ACE” is a subsequence of “ABCDE” while “AEC” is not).

Example 1:

Input: S = “rabbbit”, T = “rabbit”
Output: 3
Explanation:
As shown below, there are 3 ways you can generate “rabbit” from S.
(The caret symbol ^ means the chosen letters)
rabbbit
^^^^ ^^
rabbbit
^^ ^^^^
rabbbit
^^^ ^^^

Example 2:

Input: S = “babgbag”, T = “bag”
Output: 5
Explanation:
As shown below, there are 5 ways you can generate “bag” from S.
(The caret symbol ^ means the chosen letters)
babgbag
^^ ^
babgbag
^^ ^
babgbag
^ ^^
babgbag
^ ^^
babgbag
^^^

解析

找到字符串s中子串t的个数。

自己的解法

设一个二维数组dp[t.len][s.len],dp[i][j]表示字符串s[0,j]有子串t[0,i]的个数,只有s[j]==t[i]时,才会>0;
当匹配到t的第i+1个字符时,当前与t[i+1]相同的字符位置s[j]的dp[i+1][j]是上一个匹配字符的个数之和,即dp[i+1][j] = dp[i][k] k<j;
最后结果为t的最后一个字符全部匹配的结果之和。

class Solution {
public:
    int numDistinct(string s, string t) {
        int len1 = s.size(),len2 = t.size();
        if(len1 == 0 || len1 < len2)
            return 0;
        vector<vector<long> > dp(len2, vector<long>(len1,0));
        for(int i=0;i<len2;i++){
            for(int j=0;j<len1;j++){
                if(t[i] == s[j]){
                    if(i == 0)
                        dp[0][j] = 1;
                    else{
                        for(int k=0;k<j;k++)
                            dp[i][j] += dp[i-1][k];
                    }
                }
            }
        }
        int res = 0;
        for(int j=0;j<len1;j++)
            res += dp[len2-1][j];
        return res;
    }
};

动态规划

同样设置一个动态规划数组,dp[i][j] 表示s中范围是 [0, i] 的子串中能组成t中范围是 [0, j] 的子串的子序列的个数。
边界条件:子序列为空时,返回1,即dp[0][j] = 1
dp[i][j] 时,dp[i][j] >= dp[i][j - 1] 总是成立,
当 T[i - 1] == S[j - 1] 时,dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1],
若不等, dp[i][j] = dp[i][j - 1],
综合以上,递推式为:
dp[i][j] = dp[i][j - 1] + (T[i - 1] == S[j - 1] ? dp[i - 1][j - 1] : 0)

class Solution {
public:
    int numDistinct(string s, string t) {
        int len1 = s.size(),len2 = t.size();
        if(len1 == 0 || len1 < len2)
            return 0;
        vector<vector<long> > dp(len2+1, vector<long>(len1+1,0));
        for(int i=0;i<=len2;i++){
            for(int j=i;j<=len1;j++){
                if(i == 0) dp[i][j] = 1;
                else{
                    dp[i][j] = t[i-1] == s[j-1] ? dp[i][j-1]+dp[i-1][j-1] : dp[i][j-1];
                }
            }
        }
        return dp[len2][len1];
    }
};

参考

https://www.cnblogs.com/grandyang/p/4294105.html

STM32F103C8T6驱动DHT11温湿度传感器程序 本程序基于 STM32F103C8T6 微控制器,通过 GPIO 模拟单总线通信时序实现对 DHT11 温湿度传感器的数据采集,主机采用拉低数据线的方式触发传感器启动,并通过检测高电平持续时间区分逻辑“0”和“1”,依次读取湿度和温度的整数数据及校验位,经过校验后将有效结果存入缓存数组,实现对环境温湿度的周期性测量与处理。 阅读详情

相关推荐

前端监控体系:从Sentry到LogRocket错误追踪

Sentry是一款开源的实时错误追踪系统,支持多种语言和框架,包括JavaScript、React、Vue等。它提供了丰富的错误信息、堆栈跟踪和环境数据,帮助开发者快速定位和解决问题。LogRocket是一款前端监控和用户行为分析工具,它提供了视频回放、性能监控、错误追踪等功能。与Sentry不同,LogRocket更注重用户行为的全面分析。前端监控体系是确保应用稳定性和用户体验的重要保障。通过集成Sentry和LogRocket等监控工具,开发者可以实时追踪应用中的错误和用户行为,快速定位和解决问题。

shejizuopin的博客 1316

LeetCode 37 Distinct Subsequences

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

936

串并装换器的设计及仿真结果

串/并转换是高速数据流处理的重要技巧之一。串/并转换的实现方法多种多样,根据数据的的顺序和数量要求,可以选用寄存器,双扣RAM,SRAM,FIFO,等实现。对于 数量比较小的设计可以采用移位寄存器完成串/并转换。       在工程中,如何体现串/并转换的设计思想呢? 怎样才能提高系统的处理速度呢 ?       一个简单的串/并转换框架如下图所示,串行输入的数据通过FPGA内部的 n 个移

stubben_bear的专栏 2273

LeetCode 115. Distinct Subsequences(动态规划)

Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string...

da_kao_la的博客 404

别再让COGI拖慢你的SAP接口!手把手教你配置BAPI_PRODORDCONF_CREATE_TT的同步货物移动

本文深入解析SAP生产订单报工接口中的COGI问题,通过BAPI_PRODORDCONF_CREATE_TT的同步配置实战,解决异步更新导致的性能瓶颈。文章详细介绍了增强点配置和性能验证,帮助用户彻底消除COGI堆积,提升接口效率。

weixin_29214691的博客 482

大数据国赛第2套任务C-子任务一特征工程

根据**Hudi**的dwd_ds_hudi库中相关表或MySQL中shtd_store中相关表(order_detail、sku_info),计算出与用户id为6708的用户所购买相同商品种类最多的前10位用户(只考虑他俩购买过多少种相同的商品,不考虑相同的商品买了多少次),将10位用户id进行输出,若与多个用户购买的商品种类相同,则输出结果按照用户id升序排序,输出格式如下,将结果截图粘贴至客户端桌面【Release任务C提交结果.docx】中对应的任务序号下;

weixin_44117248的博客 904

Leetcode 115 Distinct Subsequences(DP)

题目连接:Leetcode 115 Distinct Subsequences解题思路:dp[i][j]表示s[0]~s[j]匹配前i个字符有多少种方式(s[j]一定匹配t[i]),dp[i][j] = sum(dp[i-1][k]) 其中k&lt;j,如果s[j] != t[i] 的话,dp[i][j] = 0。最后可以省略一层dp状态。class Solution { public: i...

不慌不忙、不急不躁 317

Docker容器n8n中 read/write files from disk 无法读取容器内文件解决方案

《n8n文件读写Docker部署常见问题解决方案》摘要:针对n8n 1.90.2版本在Docker环境下文件读写失败问题,本文分析常见错误包括路径错误(ENOENT)、权限不足(EACCES)及节点误用问题。核心解决方案为:1)通过-v参数挂载宿主机目录到容器(如/files);2)使用新版Read/WriteFilesfromDisk节点操作文件;3)确保权限设置正确。提供可直接导入的示例工作流JSON,演示从CSV读取到结构化数据处理的全流程。特别强调已部署用户需重新挂载卷的正确操作方式,并附解决方案对

m0_74822402的博客 2184

LeetCode力扣之115. Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (can ...

LeeWei 317

Vivado实战:如何用BUFGMUX_CTRL实现FPGA双时钟热切换(附时序约束模板)

本文详细介绍了如何使用Xilinx FPGA中的BUFGMUX_CTRL原语实现双时钟热切换的工业级解决方案。通过分析BUFGMUX_CTRL的核心机制、PCB布局约束和电源噪声抑制方法,提供Vivado实现全流程和时序约束模板,帮助工程师在工业自动化、车载电子等场景中提升系统可靠性。

weixin_29186249的博客 578

MFC属性网格控件(CMFCPropertyGridCtrl)完全指南:构建专业属性编辑界面

本文详细介绍了MFC中的CMFCPropertyGridCtrl控件的使用方法。主要内容包括:控件基础用法(初始化、添加属性、事件处理)、高级设置(自定义外观、创建属性类型、动态更新)、派生类实现(自定义绘制、搜索过滤功能)、界面集成技巧(对话框布局、属性编辑器)以及实际应用示例。文章重点讲解了如何通过继承和自定义实现复杂功能,并提供了性能优化、多语言支持等最佳实践方案。该控件适用于需要大量参数配置的应用程序,能够创建类似Visual Studio属性窗口的专业界面。

专注现代C++实战,从核心语法到高性能编程,助力开发者深入掌握系统级编程精髓。 155

LeetCode115—Distinct Subsequences

Distinct Subsequences

上善若水 581

Matlab仿真:均匀面阵方向图、均匀线阵方向图、均匀圆阵方向图

其中,阵列方向图是评价阵列性能的重要参数之一。均匀面阵由若干个相同的阵元构成,阵元间等距排列,阵元的方向图形状为一个圆盘。均匀线阵由若干个相同的阵元构成,阵元间等距排列,阵元的方向图形状为一个矩形。本文将采用Matlab进行仿真,分别实现均匀面阵方向图、均匀线阵方向图和均匀圆阵方向图,并对三种阵列进行比较分析。通过以上代码仿真,我们可以对均匀面阵、均匀线阵和均匀圆阵进行方向图的绘制,进一步分析不同阵列在天线性能方面的差异。Matlab仿真:均匀面阵方向图、均匀线阵方向图、均匀圆阵方向图。

2301_79326857的博客 3437

Leetcode 115 Distinct Subsequences

思路一: 不容易啊,自己做出backtracking(dfs)的hard题。哈哈其实我是事先知道了这题要用dfs来做所以才直接往这方向靠的,不然的话也不一定我就能想到dfs。其实朝着dfs方向去想还是很容找到规律的。准确的说这边是使用了recursion and memorization,光用recursion会acception denied,因为time limit exceeded。下面简单说一下自己的思路吧:base case有两个,一个是当s长度小于t长度,返回0;另一个是当t的长度为1,只需简.

GoodJobJasper的博客 258

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode //C - 115. Distinct Subsequences

【代码】LeetCode //C - 115. Distinct Subsequences。

Made in Code 1342

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode(115) Distinct Subsequences

题目如下: Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can

BUILD 3858

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LeetCode 115. Distinct Subsequences

题目链接:不同的子序列 - 力扣 (LeetCode) Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original ...

zhaohaibo的博客 346

LeetCode115 Distinct Subsequences

详细见:leetcode.com/problems/distinct-subsequences Java Solution: github package leetcode; /* * Given a string S and a string T, count the number of distinct subsequences of * T in S. A s

zxwtry的博客 496

【LeetCode 115 Distinct Subsequences】

Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string by deleting some (ca...

lqy0927的博客 278

【Leetcode】115. Distinct Subsequences

位整数范围内,中间产生的答案仍然有可能超界的,比如。稍微聪明点的办法是,直接将每次的答案模。作为子序列出现了多少次。这道题需要注意一下,即使最终答案在。也非常长,但非常后面的地方有个。的值有可能会非常大以至于超出了。作为子序列,合起来就能拼成。时间复杂度一样,空间。

数学、算法爱好者的博客 261

LeetCode(115) Distinct Subsequences

题目 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (ca

指尖飞舞 3298

LeetCode 115 Distinct Subsequences 不同子串

LeetCode 115 Distinct Subsequences 不同字串 题目 Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of

andyL_05的博客 364

leetcode-115. Distinct Subsequences

题目链接:点击打开链接 解: 代码C++: #include #include #include #include #include #include #include using namespace std; const int N = 10000; int table[N][N] = {0}; int numDistinct(string s, stri

surbeyond的专栏 346

[LeetCode] 115. Distinct Subsequences

[LeetCode] 115. Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original str

ouwenjie10的专栏 282

【LEETCODE】115- Distinct Subsequences [Python]

题目: https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is

aliceyangxi1987的博客 1002

Leetcode 115. Distinct Subsequences

原题:Given a string S and a string T, count the number of distinct subsequences ofS which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (ca...

muche001的专栏 215
上一篇: [leetcode] 97. Interleaving String
下一篇: [leetcode] 128. Longest Consecutive Sequence
Peng_maple
博客等级 码龄10年 0粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值