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 ...
随机推荐
- docker 容器 centos + tomcat + jdk
环境: 阿里云ecs服务器 步骤: 1.安装docker 2.获取centos镜像 3.下载tomcat 和 jdk 安装包 4.配置 1.安装docker https://www.cnblogs.c ...
- 在 Linux 服务器上部署 nginx 之后不能访问
原文地址:https://blog.csdn.net/lipeigang1109/article/details/73295373 解决办法:https://jingyan.baidu.com/art ...
- 批处理 进行svn代码拉取,vs编译,dotfuscator混淆
Dotfuscator的使用:https://www.cnblogs.com/aitong/p/10684004.html 从拉取代码,编译到最后的混淆步骤很多.这时就可以使用批处理来进行自动化. 用 ...
- QT 相关
Qt是一个GUI框架,在GUI程序中,主线程也叫GUI线程,因为它是唯一被允许执行GUI相关操作的线程.对于一些耗时的操作,如果放在主线程中,就是出现界面无法响应的问题. 解决方法一:在处理耗时操作中 ...
- epoll_wait 返回值学习以及epoll使用学习
https://blog.csdn.net/analogous_love/article/details/88721574
- maven打包时跳过测试类
记录 修改pom.xml文件 <project> [...] <build> <plugins> <plugin> <groupId>org ...
- 项链(burnside)
Description 有一个长度为 \(n\) 的项链,首尾相接形成环,现在你要给每一个位置一个颜色 \([1,m]\), 求所有不同的项链个数(可以通过旋转变成一样的称为相同) Solution ...
- Mybatis JdbcType与Oracle、MySql数据类型对应列表
1. Mybatis JdbcType与Oracle.MySql数据类型对应列表 Mybatis JdbcType Oracle MySql JdbcType ARRAY JdbcType B ...
- Yii框架配置语言包
配置文件frontend\config\main.php 'language' => 'zh-CN', //配置语言包 'i18n' =>[ 'translations' => [ ...
- 测试域名ping延迟脚本
#!/bin/bash if [ $# -lt 1 ]thenecho "Usage:avg file1"exit 1fiecho "================== ...