这道题采用动态规划,可是我一开始没有想到。后来参考了discuss中前辈的代码和思路,才想通的。
方法二是因为每一步只和上一步的内容相关,所以可以只用O(n)的空间复杂度。下面是AC代码: 1 /** 2 * Solution DP 3 * we keep
a m*n matri...
分类:
其他好文 时间:
2014-05-10 08:43:12
阅读次数:
319
一.最长公共子序列(LCS Longest Common
Subsequence)第一,先说区别,最长公共子串和最长公共子序列是不一样的。最长公共子串不许是连续的,而最长公共子序列可以是不联系的。网络上解释的子序列:一个字符串S,去掉零个或者多个元素所剩下的子串称为S的子序列。最长公共子序列就是寻找...
分类:
其他好文 时间:
2014-05-10 01:12:20
阅读次数:
370
转自http://www.cnblogs.com/qixuejia/archive/2010/07/14/1777105.html1.聚合函数(1)AVG函数功能返回组中值的平均值。空值将被忽略语法AVG([
ALL | DISTINCT ] expression)(2)MAX函数功能返回表达式的最...
分类:
数据库 时间:
2014-05-05 23:23:05
阅读次数:
560
最长公共子系列,简单的dp,不过注意有空格,所以,在读字符串的时候,尽量用gets读,这样基本没问题#include#include#include#includeusing
namespace std;int dp[1001][1001];int MAX(int x,int y){ if (...
分类:
其他好文 时间:
2014-05-04 11:34:41
阅读次数:
294
维护两个单调队列,一个存储当前点之前的最大值。
另外一个存储当前点之前的最小值。
若最大值与最小值之间的差大于k,那么就把最大值和最小值中位置靠前的往后移。
#include
#include
#include
#include
#include
using namespace std;
//#define INF ((1<<30)-1)
#define INF 0xfffff
#defin...
分类:
其他好文 时间:
2014-05-04 09:23:04
阅读次数:
372
最近在学scala语言,scala代码如下:
import scala.collection.JavaConversions._
object Solution {
def solution(A: Array[Int]): Int = {
// write your code in Scala 2.10
// using quick sort to so...
分类:
其他好文 时间:
2014-05-04 09:22:37
阅读次数:
341
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets
so as the following conditions hold:
The product of all numbers in the first set is less ...
分类:
其他好文 时间:
2014-05-03 23:51:19
阅读次数:
621
题目:
Given a string S and a string T, count the number of distinct subsequences of T in S.
A subsequence of a string is a new string which is formed from the original string by deleting some (c...
分类:
其他好文 时间:
2014-05-03 21:48:19
阅读次数:
252
1、能用DISTINCT的就不用GROUP BY
SELECT OrderID FROM Details WHERE UnitPrice > 10 GROUP BY OrderID
可改为: SELECT DISTINCT OrderID FROM Details WHERE UnitPrice > 10
2.能用UNION ALL就不要用UNION
UNION A...
分类:
数据库 时间:
2014-05-03 21:31:24
阅读次数:
342
Given a set of distinct integers, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.
For exa...
分类:
其他好文 时间:
2014-05-03 15:47:53
阅读次数:
289