摘要: 这个题相当经典。很多题目都可以等价过来。一、简单的O(n^2)的算法 很容易想到用动态规划做。设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i>j。然后在lis[]中找到最大的一个值,时间复杂度是O(n^2)。int Longest_Increasing(int num[],int n){ int lis[n],i,j; for(i=0;inum[j]&&lis[j]+1>lis[i]) lis[i]=lis[j]+1; } int ma... 阅读全文
posted @ 2014-04-10 15:04 linyx 阅读(447) 评论(0) 推荐(0) 编辑
摘要: The algorithm for evaluating any postfix expression is fairly straightforward:While there are input tokens leftRead the next token from input.If the t... 阅读全文
posted @ 2014-04-10 14:17 linyx 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be ch... 阅读全文
posted @ 2014-04-10 12:23 linyx 阅读(341) 评论(0) 推荐(0) 编辑
摘要: Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the p... 阅读全文
posted @ 2014-04-10 11:34 linyx 阅读(187) 评论(0) 推荐(0) 编辑