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 ...
随机推荐
- 在win7系统设置SQL Server2014 express为远程数据
如何设置远程访问到SQLserver服务器(局域网内的设置) 1.首先,使用Windows+R键 输入services.msc 打开本地服务. *说明:①MSSQLSERVER是正式使用的SQL创建实 ...
- java se系列(十一)线程
1 线程的概述 进程:正在运行的程序,负责了这个程序的内存空间分配,代表了内存中的执行区域. 线程:就是在一个进程中负责一个执行路径. 多线程:就是在一个进程中多个执行路径同时执行. 图上的一键优化与 ...
- 使用kerl安装erlang遇到的问题及解决办法-bak
1 需要安装相关包 -dev autoconf 2 出现下面错误 * documentation : * xsltproc is missing. * fop is missing. * xmllin ...
- 【CSS】 布局之剖析负边距
我们都知道,一个元素框的大小是由元素内容+内边距+边框+外边距来决定的. 关于内边距padding,内边距呈现了元素的背景,其设置值是不可以为负的. 而对于外边距margin,默认为透明,设置值可以为 ...
- Unity Github 项目收集
http://gad.qq.com/article/detail/24048 重磅推荐: Github 热门 Unity Assets 查询:http://unitylist.com/browse 最 ...
- SQL Cookbook—字符串
1.遍历字符串2.计算字符在字符串中出现的次数3.从字符串中删除不需要的字符4.将字符和数字数据分离5.判别字符串是不是字母数字型的6.提取姓名的大写首字母缩写7.按字符串中的部分内容排序8.按字符串 ...
- EF 连接到 Azure-SQL
using Autofac; using Autofac.Integration.Mvc; using System; using System.Collections.Generic; using ...
- Java中break、continue及标签等跳转语句的使用[下]
作为上一篇使用for循环演示的跳转,这一篇将使用while.相比较来说,while比for循环更简单.代码如下: public class LabeledWhile { public static v ...
- resteasy上传单个文件/多个文件到阿里云服务器
代码如下: ExcelServerController.java package com.xgt.controller; import com.xgt.bean.bs.ExcelBean; impor ...
- MySQL之函数
了解编程的人一般都会知道函数的重要性,丰富的函数有的时候可以给我们带来事半功倍的效果,在MySQL中提供了许多的内置函数,能够帮助开发人员编写简单快捷的SQL语句,除了这些内置的函数之外,用户也可以自 ...