leetcode-distinct sequences
- 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的更多相关文章
- 子序列 sub sequence问题,例:最长公共子序列,[LeetCode] Distinct Subsequences(求子序列个数)
引言 子序列和子字符串或者连续子集的不同之处在于,子序列不需要是原序列上连续的值. 对于子序列的题目,大多数需要用到DP的思想,因此,状态转移是关键. 这里摘录两个常见子序列问题及其解法. 例题1, ...
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- [leetcode]Distinct Subsequences @ Python
原题地址:https://oj.leetcode.com/problems/distinct-subsequences/ 题意: Given a string S and a string T, co ...
- Leetcode Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- [LeetCode] Distinct Subsequences 解题思路
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- LeetCode: Distinct Subsequences [115]
[称号] Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequ ...
- LeetCode: Distinct Subsequences 解题报告
Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of ...
- [LeetCode] Distinct Subsequences [29]
题目 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequen ...
- [Leetcode] distinct subsequences 不同子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- Solution to LeetCode Problem Set
Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...
随机推荐
- 899. Orderly Queue
A string S of lowercase letters is given. Then, we may make any number of moves. In each move, we c ...
- 解决centos被minerd挖矿程序入侵方法
记录一次服务器被入侵的解决方法 一:问题说明 1.我的服务器是使用的阿里云的CentOS,收到的阿里云发来的提示邮件如下 然后我查看了运行的进程情况(top 命令),看到一个名为minerd的进程占用 ...
- 理解restful 架构 && RESTful API设计指南
restful是前端和后端接口中都会使用的设计思想. 网站即软件,我们也常说的webapp,这种互联网软件采用的是“客户端/服务器”模式,建立在分布式体系上. 网站开发,也可以完全采用软件开发的模式, ...
- javascript正则表达式语法
1. 正则表达式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有特殊定义的标点符号,都是"普通字符".表达式中的普通字符,在匹配一个字符串的时候,匹配与之相同的 ...
- JPA为字段设置默认值
http://blog.csdn.net/u011983531/article/details/51286839 在使用JPA时,如果需要为属性设置默认值,很自然的,你可能会想到用下面的方式. @Co ...
- php对图片加水印--将一张图片作为水印加到另一张图片
代码如下: /** * 图片加水印(适用于png/jpg/gif格式) * * @param $srcImg 原图片 * @param $waterImg 水印图片 * @param $s ...
- 启停无线网卡bat脚本
@echo off color 2 title 启停无线网卡 echo 启动无线网卡=======>按1键 echo 关闭无线网卡=======>按2键 set /p n= if /i & ...
- 开窗函数over()
使用方法 如:select name,avg(shengao)from xinxi group by name //我们都知道使用聚合函数要使用分组,如果不分组怎么办 Selct name,avg(s ...
- golang学习之struct
结构体定义的一般方式如下: type identifier struct { field1 type1 field2 type2 ... } type T struct {a, b int} 也是合法 ...
- PHP5中Static和Const关键字
(1) static static要害字在类中是,描述一个成员是静态的,static能够限制外部的访问,因为static后的成员是属于类的,是不属于任何对象实例,其他类是无法访问的,只对类的实例共享, ...