Solution: when see question about two strings , DP should be considered first.
We can abstract this question to calculate appear times for string T with length i in string S with length j, which can be represented by numbers[i][j], then through observation and thinking , we can know for numbers[i][j] it should at least equal the numbers[i][j-1] and if T.charAt(i)==S.charAt(j) , numbers[i][j] should also be add numbers[i-1][j-1]
 
 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

最新文章

  1. 深入理解javascript原型和闭包(9)——简述【执行上下文】下
  2. MySQL检查重复索引工具-pt-duplicate-key-checker
  3. 彻底解决m2eclipse之Unable to update index for central
  4. 【php】使用phpdbg来调试php程序
  5. Open经验库网址
  6. Android中级之网络数据解析一之xml解析
  7. Linux 查看版本详情
  8. 关于C#正则表达式MatchCollection类的总结,正则表达式的应用
  9. chrome开发工具指南(六)
  10. 【转载】基于VoiceOver的移动web站无障碍访问实战
  11. poj-2909-哥德巴赫猜想
  12. centos7.2安装完成的基本操作
  13. Kettle Spoon入门教程
  14. eclipse下安装windowbuilder(一定要看)
  15. markdown的css样式(自己写的)
  16. 对CountDownLatch的初步学习
  17. win8 下面 listen 的队列长度貌似无效了 上c/s 代码 并附截图,有图有真相
  18. 隐藏windows任务栏中的窗口显示
  19. python基础之字符串格式化
  20. 自适应滤波:维纳滤波器——FIR及IIR设计

热门文章

  1. Html checkbox全选
  2. cv2.FileNode has no keys
  3. sql 获取当天开始时间 结束时间
  4. 基于web端去除空格小工具
  5. Android创建定时和周期任务
  6. MySQL通过SQL语句来直接生成新表
  7. shell之“&gt;/dev/null 2&gt;&amp;1” 详解
  8. React.js 小书 Lesson26 - 实战分析:评论功能(五)
  9. [转]asp.net5中使用NLog进行日志记录
  10. 三年从前端小工到架构-知乎 Live 学习整理