1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年12月30日

摘要: 暴力= =枚举断开位置...据说可以dp,等下试试class Solution {public: bool isPal(const string& s , int start , int end){ end --; while(start > &ans , vector& path , int prev , int end){ if(end >= s.size()){ if(isPal(s , prev , end)){ path.push_back(s.substr(prev , end-p... 阅读全文

posted @ 2013-12-30 20:27 1957 阅读(142) 评论(0) 推荐(0) 编辑

摘要: 经典的最大子段和状态表示f[i]表示以A[i]结尾的最大子段和是多少.可想而知,如果f[i-1] > 0那么是对第i位是有贡献的。f[i] = f[i-1] + A[i]不然...f[i]= A[i]class Solution {public: int maxSubArray(int A[], int n) { vector f(n , 0); f[0] = A[0]; int ans = f[0]; for(int i = 1 ; i 0) f[i] = f[i-1] + A[i]; el... 阅读全文

posted @ 2013-12-30 19:19 1957 阅读(120) 评论(0) 推荐(0) 编辑

摘要: 经典dp....可以不用extra空间的,既然要求只能用O(n)...那估计想考滚动数组吧那就那么写吧。。。class Solution {public: int minimumTotal(vector > &triangle) { int n = triangle.size(); if(n == 0) return 0; int m = triangle[n - 1].size(); vector > f(2 , vector(m , INT_MAX)); int mark = 0; f... 阅读全文

posted @ 2013-12-30 18:44 1957 阅读(142) 评论(0) 推荐(0) 编辑

摘要: /** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int... 阅读全文

posted @ 2013-12-30 18:22 1957 阅读(156) 评论(0) 推荐(0) 编辑

摘要: 很简单...都做过...不过让就用A,B这两个数组,一下忘了...思维习惯就是去选小的啦,其实我们可以选大的放到最后不就好处理了!class Solution {public: void merge(int A[], int m, int B[], int n) { int la... 阅读全文

posted @ 2013-12-30 10:49 1957 阅读(126) 评论(0) 推荐(0) 编辑

摘要: 和I一样的...只是把bool数组改成int数组,记录下次数就好了...不过为毛是最优我还没有证明...意识流吧...class Solution {public: int jump(int A[], int n) { vector f(n , 0); int maxi = 0; for(int i = 0 ; i 0 || i == 0){ if(i + A[i] > maxi){ for(int j = maxi + 1 ; j <= i + A[i]&& j<n; j++... 阅读全文

posted @ 2013-12-30 10:18 1957 阅读(89) 评论(0) 推荐(0) 编辑

摘要: 开始想法扫描一次。。。然后再标记一次。。。O(n^2)但是。。。TLE啦。。。太暴力了。。。其实只要标记过了的,我们就不用处理了。。。然后如果到达一个可到达的地方,而且要jump到没有标记的地方,那么我们再标记吧,O(n)class Solution {public: bool canJump(int A[], int n) { vector f(n,false); f[0] = true; int maxi = 0; for(int i = 0 ; i maxi) { ... 阅读全文

posted @ 2013-12-30 01:31 1957 阅读(149) 评论(0) 推荐(0) 编辑