2020-01-03 13:29:04

问题描述:

问题求解:

经典的动态规划题目,一般来说dp题目是递推关系公式难想,但是实际代码量还是比较少的。

有尝试过dfs来做,但是由于时间复杂度是指数级别的,所以会TLE。

    public int numDistinct(String s, String t) {
int n1 = s.length();
int n2 = t.length();
int[][] dp = new int[n2 + 1][n1 + 1];
for (int i = 0; i <= n1; i++) dp[0][i] = 1;
for (int i = 1; i <= n2; i++) {
for (int j = 1; j <= n1; j++) {
if (t.charAt(i - 1) == s.charAt(j - 1)) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
else dp[i][j] = dp[i][j - 1];
}
}
return dp[n2][n1];
}

  

动态规划-Distinct Subsequences的更多相关文章

  1. 动态规划——Distinct Subsequences

    题目大意:给定字符串S和T,现在从S中任选字符组成T,要求输出方案个数. Example 1:Input: S = "rabbbit", T = "rabbit" ...

  2. LeetCode 笔记22 Distinct Subsequences 动态规划需要冷静

    Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of  ...

  3. Distinct Subsequences ——动态规划

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

  4. LeetCode之“动态规划”:Distinct Subsequences

    题目链接 题目要求: Given a string S and a string T, count the number of distinct subsequences of T in S. A s ...

  5. Distinct Subsequences(不同子序列的个数)——b字符串在a字符串中出现的次数、动态规划

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

  6. [LeetCode] Distinct Subsequences 不同的子序列

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

  7. Leetcode Distinct Subsequences

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

  8. LeetCode(115) Distinct Subsequences

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

  9. [Leetcode][JAVA] Distinct Subsequences

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

随机推荐

  1. 基于物理的渲染——间接光照

    在前面的文章中我们已经给出了基于物理的渲染方程: 并介绍了直接光照的实现.然而在自然界中,一个物体不会单独存在,光源会照射到其他的物体上,反射的光会有一部分反射到物体上.为了模拟这种环境光照的形式,我 ...

  2. 剑指offer-18-2. 删除链表中重复的结点

    剑指offer-18-2. 删除链表中重复的结点 链表 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3-> ...

  3. 在虚拟机单机部署OpenStack Grizzly

    安装过程 安装Ubuntu 我手头有的是Ubuntu Server 12.04 64位版,就直接用了,默认安装即可,配置的时候很简单,如下 内存:1G 硬盘:20G 处理器:2 网络:NAT 装好以后 ...

  4. Picaso完美兼容OkHttp3.3,缓存优化两不误 - Tamic Developer"s Blog

    为何在Fresco,Glide这么强大的背景下,我又想起了当初的Picasso,又为何写这篇文章?是因为最近项目采用了square公司的RxAndroid,Retrfit和OKhttp, 不得不联想到 ...

  5. ip修改成域名

    将ip修改成域名,这样的话可以使程序变得更加健壮,别人不能直接看见你的ip地址. 后来总结下分享给大家.首先找到hosts文件的位置,这个文件是系统dns默认查找的文件. windows 系统:C:\ ...

  6. 浏览器内核之 HTML 解释器和 DOM 模型

    微信公众号:爱写bugger的阿拉斯加如有问题或建议,请后台留言,我会尽力解决你的问题. 前言 此文章是我最近在看的[WebKit 技术内幕]一书的一些理解和做的笔记.而[WebKit 技术内幕]是基 ...

  7. CSS 图像拼合技术(雪碧图)

    1.css 图像拼合 图像拼合就是单个图像的集合. 有许多图像的网页可能需要很长的时间来加载和生成多个服务器的请求. 使用图像拼合会降低服务器的请求数量,并节省带宽. 代码如下: <!docty ...

  8. H5开发移动应用APP(店铺系列一)

    首先,这是个真实的案例,我大兄弟在深圳开汽修店铺,但需要系统来管理日常经营活动,这正不是我擅长的吗? 说干就干,直接后端+web端+移动端来一套,于是紧急赶工,起早摸黑,产出约3万行总量代码,此系统与 ...

  9. 全面认识HBase架构(建议收藏)

    在网上看过很多HBaes架构相关的文章,内容深浅不一,直到发现了一篇MapR官网的文章https://mapr.com/blog/in-depth-look-hbase-architecture/#. ...

  10. [pdo_mysql.lo] Error 1 或者 [php_mysql.lo] Error 1

    make: *** [pdo_mysql.lo] Error 1 make: *** [php_mysql.lo] Error 1 这是因为这是因为在编译时需要 MySQL 的头的文件.而它按默认搜索 ...