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.

题意:求S中所有子串中与T相同的有多少个

空串是任意字符串的子串。

代码:

  class Solution {
public:
int numDistinct(string S, string T) {
int row=S.size()+;
int col=T.size()+;
vector<int> temp(col,);
vector<vector<int>> dp(row,temp);
dp[][]=;
for(int i=;i<row;++i) dp[i][]=; for(int i=;i<row;++i){
for(int j=;j<=i&&j<col;++j){
if(S[i-]==T[j-]){
dp[i][j]=dp[i-][j-]+dp[i-][j];
}else{
dp[i][j]=dp[i-][j];
}
}
}
return dp[row-][col-];
}
};

Distinct Subsequences (dp)的更多相关文章

  1. uva 10069 Distinct Subsequences(高精度 + DP求解子串个数)

    题目连接:10069 - Distinct Subsequences 题目大意:给出两个字符串x (lenth < 10000), z (lenth < 100), 求在x中有多少个z. ...

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

  3. uva 10069 Distinct Subsequences 【dp+大数】

    题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...

  4. UVa 10069 Distinct Subsequences(大数 DP)

     题意 求母串中子串出现的次数(长度不超过1后面100个0  显然要用大数了) 令a为子串 b为母串 d[i][j]表示子串前i个字母在母串前j个字母中出现的次数   当a[i]==b[j]&am ...

  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(115) Distinct Subsequences

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

  7. [Leetcode][JAVA] Distinct Subsequences

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

  8. Distinct Subsequences Leetcode

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

  9. 【LeetCode OJ】Distinct Subsequences

    Problem Link: http://oj.leetcode.com/problems/distinct-subsequences/ A classic problem using Dynamic ...

随机推荐

  1. Big Data Mindmap

  2. Android(java)学习笔记179:多媒体之加载大图片到内存(Bitmap API)

    1. Bitmap (API使用) android里面的bitmap中,一个像素点需要4个byte去表示,这是因为android表示颜色是" argb ":其中 a 表示是透明度, ...

  3. Python3基础教程(十八)—— 测试

    编写测试检验应用程序所有不同的功能.每一个测试集中在一个关注点上验证结果是不是期望的.定期执行测试确保应用程序按预期的工作.当测试覆盖很大的时候,通过运行测试你就有自信确保修改点和新增点不会影响应用程 ...

  4. jeecms标签

    .@cms_content_list--新闻单页 [@cms_content channelId=' dateFormat='MM-dd' ] [#if tag_list?size>0] < ...

  5. vux安装

    1. 在项目里安装vux cnpm install vux --save 2. 安装vux-loader cnpm install vux-loader --save-dev 3. 安装less-lo ...

  6. C++构造函数(复制构造函数)、析构函数

    注:若类中没有显示的写如下函数,编译会自动生成:默认复制构造函数.默认赋值构造函数(浅拷贝).默认=运算符重载函数(浅拷贝).析构函数: 1.默认构造函数(默认值)构造函数的作用:初始化对象的数据成员 ...

  7. JAVA基础——网络编程之网络链接

    一.网络编程基本概念 1.OSI与TCP/IP体系模型 2.IP和端口 解决了文章最开始提到的定位的问题. IP在互联网中能唯一标识一台计算机,是每一台计算机的唯一标识(身份证):网络编程是和远程计算 ...

  8. Sqlserver查询结果集插入新表

    数据库“Test” 数据库“Test2” 表 “fromTable” 表 “toTable” 表 “newTable” 字段 “name”,“age”,“gender” 原因:公司有2个数据库,一个是 ...

  9. 03pandas

    一.pandas简述 1)pandas是一个开源的,BSD许可的库,为Python编程语言提供高性能,易于使用的数据结构和数据分析工具. 2)numpy能够帮助我们处理数值,但是pandas除了处理数 ...

  10. UVa-1339-古老的密码

    这题的话,我们可以把字符串序列里面的字母直接计数,然后比较两个数组里面的数字是否一一相同,然后就可以直接判定YES or NO. 因为它题目中说的就是一种映射的关系,首先我们读入之后,把两个字符串的不 ...