06 2014 档案

摘要:where vs having当一个sql语句中存在where子句,会先执行where,然后执行group by,然后执行having.一般来说,only use 'having' when you use 'group by'Always use 'having' with aggregate f... 阅读全文
posted @ 2014-06-29 13:49 门对夕阳 阅读(305) 评论(0) 推荐(0)
摘要:Given a list of millions of documents, how would you find all documents that contain a list of words? The words do not need to appear in any particula... 阅读全文
posted @ 2014-06-25 04:05 门对夕阳 阅读(334) 评论(0) 推荐(0)
摘要:给一堆盒子,知道每个盒子的三围(长宽高),盒子正面朝你,不能旋转摆放,按照大的放在小的下面的原则堆起来,必须是 strictly larger,同样大小的盒子不行,问怎么样堆到最大的高度?思路:动态规划最优解一定是 max( {box_1 be the bottom}, {box_2 be the ... 阅读全文
posted @ 2014-06-14 11:14 门对夕阳 阅读(664) 评论(0) 推荐(0)
摘要:Give a dynamic-programming solution to the 0-1 knapsack problem that runs inO(nW) time, where n is the number of items and W is the maximum weight ofi... 阅读全文
posted @ 2014-06-10 12:17 门对夕阳 阅读(358) 评论(0) 推荐(0)
摘要:给一个长度为 n 的杆子,切成小段卖出去,价格根据小段的长度不同而不同。下面是一个例子我们要通过切成小段卖出尽可能高的总价钱。问题是:How to decompose the problem?Decomposition 的第一步是:第一刀切在哪?可以切在最左边(等于整根卖出去);可以切在位置1,位置... 阅读全文
posted @ 2014-06-10 12:13 门对夕阳 阅读(398) 评论(0) 推荐(0)
摘要:所有的 DP 问题都可以简单得用 Recursion 的方式实现。这通常是最容易想到的思路。问题是这种实现不够 efficient,存在 subproblem 被重复计算的情况。有两种解决这个问题的方法:1. 很直观的,在 naive recursion 里加入 一个 save 的环境,把每个 su... 阅读全文
posted @ 2014-06-10 11:06 门对夕阳 阅读(292) 评论(0) 推荐(0)
摘要:Write an algorithm to print all ways of arranging eight queens on an 8*8 chess board so that none of them share the same row, column or diagonal.思路:本质... 阅读全文
posted @ 2014-06-10 03:11 门对夕阳 阅读(235) 评论(0) 推荐(0)
摘要:Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), find how many ways to represent n cents.思路:... 阅读全文
posted @ 2014-06-09 05:11 门对夕阳 阅读(485) 评论(0) 推荐(0)
摘要:Implement an algorithm to print all valid ( properly opened and closed) combinations of n-pairs of parentheses.思路:比如 n = 3, ((())) 就是一个valid combinati... 阅读全文
posted @ 2014-06-06 13:30 门对夕阳 阅读(261) 评论(0) 推荐(0)
摘要:Problem: Compute all permutations of a string of unique characters.此题用循环的方式不好做,下面是一种递归的思路:把给的字符串看成一个字符集合,每次从这个集合里拿出一个字符来填到下面的空格中。填的顺序从左到右。把a1填到第一个空格里是... 阅读全文
posted @ 2014-06-06 09:34 门对夕阳 阅读(368) 评论(0) 推荐(0)
摘要:更新到新的 Mac OS X 再打开Eclipse 编译程序会报错,Exception in thread "main" java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0原因是Eclipse 找不... 阅读全文
posted @ 2014-06-06 03:23 门对夕阳 阅读(2351) 评论(0) 推荐(0)
摘要:java.util.ArraysThis class deals with 'real' arrays in java, in the form of T[]. Thus it doesn't deal with ArrayList, java.util.Collections deals with... 阅读全文
posted @ 2014-06-05 07:21 门对夕阳 阅读(116) 评论(0) 推荐(0)
摘要:其一,所有的递归实现都可以 iteratively 实现,虽然很多时候递归的代码更简洁。其二,递归会产生多余的开销,包括空间和时间。其三,如果一定要递归,不要在一个递归函数里做多件事,最好只做一件。像下面的代码(未完成,因为写不下去了),试图在递归函数里做三件事,(1) 检测路径是否存在(2) 构造... 阅读全文
posted @ 2014-06-01 06:29 门对夕阳 阅读(388) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示