[leetcode刷题系列]Interleaving String
来源:互联网 发布:js验证11位手机号码 编辑:程序博客网 时间:2024/06/03 20:04
经典dp题,O(n^2)的状态,O(1)的转移。
const int MAXN = 1000 + 10;string s1, s2, s3;int dp[MAXN][MAXN];int is(int i, int j){ int &ret = dp[i][j]; if(i == 0 && j == 0) return 1; if(ret != -1) return ret; if(i > 0) if(s1[i - 1] == s3[i + j - 1]) if(is(i - 1, j)) return ret = 1; if(j > 0) if(s2[j - 1] == s3[i + j - 1]) if(is(i, j - 1)) return ret = 1; return ret = 0;}class Solution {public: bool isInterleave(string s1, string s2, string s3) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s1.size() + s2.size() != s3.size()) return false; ::s1 = s1; ::s2 = s2; ::s3 = s3; memset(dp, 0xff, sizeof(dp)); return is(s1.size(), s2.size()); }};
- [leetcode刷题系列]Interleaving String
- LeetCode刷题笔录Interleaving String
- LeetCode: Interleaving String
- LeetCode Interleaving String
- LeetCode: Interleaving String
- [Leetcode] Interleaving String
- [LeetCode] Interleaving String
- leetcode 68: Interleaving String
- [Leetcode] Interleaving String
- LeetCode - Interleaving String
- [LeetCode]Interleaving String
- LeetCode: Interleaving String
- Leetcode: Interleaving String
- [Leetcode]Interleaving String
- Leetcode: Interleaving String
- LeetCode:Interleaving String
- LeetCode-Interleaving String
- [leetcode] Interleaving String@DP
- hdu 1592 Half of and a Half(大数)
- ExtJS之布局篇
- [JS 最简单简洁的插件] 对话框
- Windows下GCC运用
- arcgis10.1系列软件下载_GIS520论坛
- [leetcode刷题系列]Interleaving String
- Perl的die、warn、eval函数
- EGOTableViewPullRefresh下拉原理及代码详解
- [leetcode刷题系列]Unique Binary Search Trees
- Android应用开发之(管理好你的网络操作)
- 尚学堂面试整理题目
- Merge Two Sorted Lists
- 有这样一段程序,求解???
- URAL 1430