Solution: when see question about two strings , DP should be considered first.
We can abstract this question to calculate appear times for string T with length i in string S with length j, which can be represented by numbers[i][j], then through observation and thinking , we can know for numbers[i][j] it should at least equal the numbers[i][j-1] and if T.charAt(i)==S.charAt(j) , numbers[i][j] should also be add numbers[i-1][j-1]
 
 class Solution
{
public:
int numDistinct(string S, string T) {
int sLen = S.length(); int tLen = T.length();
vector<vector<int>> dp(sLen+,vector<int>(tLen+));//dp[i][j]表示对应S前i个和T前j个字符的子问题。
for (int i = ; i <= sLen; i++) dp[i][] = ;
for (int i = ; i <= sLen; i++)
{
for (int j = ; j <= tLen; j++)
{
if (S[i - ] == T[j - ])
{
dp[i][j] = dp[i - ][j] + dp[i-][j-];
}
else
{
dp[i][j] = dp[i-][j];
}
}
}
return dp[sLen][tLen];
} };
int main()
{
Solution s;
string strS("b");
string strT("a");
cout << s.numDistinct(strS, strT) << endl;
return ;
}

http://rleetcode.blogspot.com/2014/01/distinct-subsequences-java.html

leetcode-distinct sequences的更多相关文章

  1. 子序列 sub sequence问题,例:最长公共子序列,[LeetCode] Distinct Subsequences(求子序列个数)

    引言 子序列和子字符串或者连续子集的不同之处在于,子序列不需要是原序列上连续的值. 对于子序列的题目,大多数需要用到DP的思想,因此,状态转移是关键. 这里摘录两个常见子序列问题及其解法. 例题1, ...

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

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

  3. [leetcode]Distinct Subsequences @ Python

    原题地址:https://oj.leetcode.com/problems/distinct-subsequences/ 题意: Given a string S and a string T, co ...

  4. Leetcode Distinct Subsequences

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

  5. [LeetCode] Distinct Subsequences 解题思路

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

  6. LeetCode: Distinct Subsequences [115]

    [称号] Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequ ...

  7. LeetCode: Distinct Subsequences 解题报告

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

  8. [LeetCode] Distinct Subsequences [29]

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

  9. [Leetcode] distinct subsequences 不同子序列

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

  10. Solution to LeetCode Problem Set

    Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...

随机推荐

  1. docker 容器 centos + tomcat + jdk

    环境: 阿里云ecs服务器 步骤: 1.安装docker 2.获取centos镜像 3.下载tomcat 和 jdk 安装包 4.配置 1.安装docker https://www.cnblogs.c ...

  2. 在 Linux 服务器上部署 nginx 之后不能访问

    原文地址:https://blog.csdn.net/lipeigang1109/article/details/73295373 解决办法:https://jingyan.baidu.com/art ...

  3. 批处理 进行svn代码拉取,vs编译,dotfuscator混淆

    Dotfuscator的使用:https://www.cnblogs.com/aitong/p/10684004.html 从拉取代码,编译到最后的混淆步骤很多.这时就可以使用批处理来进行自动化. 用 ...

  4. QT 相关

    Qt是一个GUI框架,在GUI程序中,主线程也叫GUI线程,因为它是唯一被允许执行GUI相关操作的线程.对于一些耗时的操作,如果放在主线程中,就是出现界面无法响应的问题. 解决方法一:在处理耗时操作中 ...

  5. epoll_wait 返回值学习以及epoll使用学习

    https://blog.csdn.net/analogous_love/article/details/88721574

  6. maven打包时跳过测试类

    记录 修改pom.xml文件 <project> [...] <build> <plugins> <plugin> <groupId>org ...

  7. 项链(burnside)

    Description 有一个长度为 \(n\) 的项链,首尾相接形成环,现在你要给每一个位置一个颜色 \([1,m]\), 求所有不同的项链个数(可以通过旋转变成一样的称为相同) Solution ...

  8. Mybatis JdbcType与Oracle、MySql数据类型对应列表

    1. Mybatis JdbcType与Oracle.MySql数据类型对应列表 Mybatis JdbcType Oracle MySql JdbcType ARRAY     JdbcType B ...

  9. Yii框架配置语言包

    配置文件frontend\config\main.php 'language' => 'zh-CN', //配置语言包 'i18n' =>[ 'translations' => [ ...

  10. 测试域名ping延迟脚本

    #!/bin/bash if [ $# -lt 1 ]thenecho "Usage:avg file1"exit 1fiecho "================== ...