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 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).

Here is an example:
S = "rabbbit", T = "rabbit"

Return 3.

class Solution {
public:
int numDistinct(string s, string t) {
int ls = s.length(), lt = t.length(), i, j;
vector<vector<int>> dp(lt+, vector<int>(ls+, ));
for(i = ; i <= ls; i++)
dp[][i] = ;
for(i = ; i <= lt; i++)
{
for(j = i; j <= ls; j++)
{
if(t[i-] == s[j-])
{
dp[i][j] = dp[i-][j-]+dp[i][j-];
}
else
{
dp[i][j] = dp[i][j-];
}
}
}
return dp[lt][ls];
}
};

注意:

“bbb”和“”的匹配结果为1。所以第一行都为1。

115. Distinct Subsequences *HARD* -- 字符串不连续匹配的更多相关文章

  1. [leetcode]115. Distinct Subsequences 计算不同子序列个数

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

  2. Leetcode 115 Distinct Subsequences 解题报告

    Distinct Subsequences Total Accepted: 38466 Total Submissions: 143567My Submissions Question Solutio ...

  3. [LeetCode] 115. Distinct Subsequences 不同的子序列

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

  4. 【LeetCode】115. Distinct Subsequences 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...

  5. 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 ...

  6. 115. Distinct Subsequences

    题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...

  7. 【一天一道LeetCode】#115. Distinct Subsequences

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  8. 115. Distinct Subsequences (String; DP)

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

  9. Java for LeetCode 115 Distinct Subsequences【HARD】

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

随机推荐

  1. wsdl客户端代码生成的方法

    在jdk的bin目录下有一个wsimport.exe的工具,使用该工具命令生产java客户端代码: 命令如下: wsimport  -keep -d d:\ -s d:\src -p com.map  ...

  2. FPN(feature pyramid networks)

    多尺度的object detection算法:FPN(feature pyramid networks). 原来多数的object detection算法都是只采用顶层特征做预测,但我们知道低层的特征 ...

  3. 97 条 Linux 常用命令及Vim命令总结

    一:Vim编辑模式命令 基本上Vim共分为3种模式,分别是一般模式,编辑模式和命令行模式,这三种模式的作用分别如下简述: 一般模式:默认模式.打开vim直接进入的是一般模式,在这个模式下,可以进行的操 ...

  4. SQL Server简洁查询正在运行SQL(等待事件)

    通常我们可以使用 sp_who2 我们希望更加简洁的信息,下面这个查询使用系统表sys.sysprocesses,以及sys.dm_exec_sql_text做OUTER APPLY. T-SQL是这 ...

  5. Linux下如何执行Shell脚本

    Linux下你可以有两种方式执行Shell脚本: 1.用shell程序执行脚本:根据你的shell脚本的类型,选择shell程序,常用的有sh,bash,tcsh等(一般来说第一行#!/bin/bas ...

  6. [py]django的manytomany字段和后台搜索过滤功能

    我本来想搞下Django之select_related和prefetch_related的区别,看到这里有djangoapi的知识, 之前搞过django restfulapi,http://blog ...

  7. SpringData修改和删除操作

    SpringData的查询我们已经学完了,我们现在就研究一下SpringData的修改和删除. @Modifying 注解和事务 @Query 与 @Modifying 这两个 annotation一 ...

  8. 92. Reverse Linked List II(链表部分反转)

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  9. 字节跳动冬令营网络赛 Solution

    A:Aloha Unsolved. B:Origami Unsolved. 题意: 初始的时候有一张纸,可以从左边往右边折叠,或者从右边往左边折叠 每次折叠的长度不能超过现有宽度,最后折叠到长度为1 ...

  10. java--jvm启动的参数

    java启动参数共分为三类其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容:其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足,且不保 ...