题意:给一串数字,问长度为m的严格上升子序列有多少个解法:首先可以离散化为10000以内,再进行dp,令dp[i][j]为以第i个元素结尾的长度为j的上升子序列的个数,则有dp[i][j] = SUM(dp[k][j-1]) (a[k] #include #include #include #inc...
分类:
其他好文 时间:
2014-09-08 02:08:16
阅读次数:
240
来源:http://www.imooc.com/code/1432continue 的作用是跳过循环体中剩余的语句执行下一次循环。例如,打印1--10 之间所有的偶数,使用 continue 语句实现代码为:运行结果:任务实现功能:求 1 到 10 之间的所有偶数的和。实现思路:定义一个变量 sum...
分类:
移动开发 时间:
2014-09-07 21:04:35
阅读次数:
205
递归,dfs这里返回值是一个pair,first表示两个子树的不经过当前root的最大pathsum;second表示两个子树的,以root->left和root->right为路径起始节点的路径的最大值 1 /** 2 * Definition for binary tree 3 * stru.....
分类:
其他好文 时间:
2014-09-07 19:43:15
阅读次数:
195
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of ...
分类:
其他好文 时间:
2014-09-07 14:40:25
阅读次数:
188
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers....
分类:
其他好文 时间:
2014-09-07 12:17:05
阅读次数:
160
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo...
分类:
其他好文 时间:
2014-09-07 11:00:24
阅读次数:
213
由于需要就地保存清零信息,所以把信息保存在第一行和第一列 1 class Solution { 2 public: 3 void setZeroes(vector > &matrix) { 4 const int ROW = matrix.size(); 5 ...
分类:
其他好文 时间:
2014-09-06 23:46:04
阅读次数:
261
一、前缀和(Prefix Sum)定义:
给定一个数组A[1..n],前缀和数组PrefixSum[1..n]定义为:PrefixSum[i] = A[0]+A[1]+...+A[i-1];
例如:A[5,6,7,8] --> PrefixSum[5,11,18,26]
PrefixSum[0] =A[0] ;
PrefixSum[1] =A[0] + A[1] ;
PrefixSum...
分类:
编程语言 时间:
2014-09-06 21:20:23
阅读次数:
897
将大小为2N的数组分成两个大小为N的数组,使得两个子数组之和最接近#includeusingnamespacestd;#definemin(a,b)(((a)n时,表示考虑到了后面n个,但是最多只能取n个。这里考虑的是从2n中取出n个,并且使得这n个之和最接近sum/2for(v=1;v=arr[k...
分类:
其他好文 时间:
2014-09-06 21:15:03
阅读次数:
324
d[i][j]表示i行j列格子可以得到的最大值顺着来的时候d[i][j]=max(d[i-1][k]+sum[k...j])=max(d[i-1][k]-sum[1..k-1]+sum[1...j]) sum[1...j]是固定值 只要找d[i-1][k]+sum[1...k] 的最大值就可以了找法...
分类:
其他好文 时间:
2014-09-06 21:10:33
阅读次数:
253