115.leetcode Distinct Subsequences(hard)[动态规划]
来源:互联网 发布:淘宝怎么出售禁售商品 编辑:程序博客网 时间:2024/06/10 12:03
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
.
题目的含义是要求T成为S的子串的形成方式的个数。组成动态规划状态数组L[t.length()+1][s.length()+1].
class Solution {public: int numDistinct(string s, string t) { if(s.length()<t.length()||t.length()==0||s.length()==0) return 0; int n = s.length(),m = t.length(); int L[m+1][n+1]; for(int i=0;i<=m;i++) for(int j=0;j<=n;j++) L[i][j] = 0; for(int j=0;j<=n;j++) L[0][j] = 1; for(int i=1;i<=m;i++) { for(int j = i; j<=n;j++) { if(s[j-1] == t[i-1]) { L[i][j] = L[i-1][j-1]+L[i][j-1]; }else L[i][j] = L[i][j-1]; } } return L[m][n]; } };
0 0
- 115.leetcode Distinct Subsequences(hard)[动态规划]
- LeetCode 115. Distinct Subsequences| 动态规划
- LeetCode Distinct Subsequences(动态规划)
- LeetCode(115) Distinct Subsequences(动态规划)
- 115. Distinct Subsequences--动态规划的方法
- Leetcode Distinct Subsequences 动态规划法活用总结
- Leetcode Distinct Subsequences 动态规划法活用总结
- LeetCode 115. Distinct Subsequences
- [Leetcode] 115. Distinct Subsequences
- [leetcode] 115.Distinct Subsequences
- [leetcode] 115.Distinct Subsequences
- Leetcode 115. Distinct Subsequences
- 【LeetCode】115. Distinct Subsequences
- LeetCode 115. Distinct Subsequences
- [leetcode]115. Distinct Subsequences
- LeetCode-115.Distinct Subsequences
- [LeetCode] 115. Distinct Subsequences
- LeetCode 115. Distinct Subsequences
- KMP字符串模式匹配详解
- Ubuntu系统(bluez)蓝牙调试
- vector和iterator的使用,排序,打印,挑选偶数
- MySQL之游标
- Java心得体会之多态
- 115.leetcode Distinct Subsequences(hard)[动态规划]
- 初识virtual memory
- 编写一个存储过程,根据学号、课程号 按成绩的20%进行加分,如果增加后的分数大于100,则取消加分。同时在存储过程中返回增加后的成绩。
- 玩无限消乐的设计示例(基础篇)填充动画元素操作
- Java----Object
- HDU 2196 Computer(树形DP)
- webpack.config.js源码解析
- 黑马程序员——Java基础——Java语言基础
- C#索引器与属性的区别,以及索引器使用方法