相比 HDOJ 的 fatmouse‘s speed 这道题只需要输出 最长子序列的长度#includeusing namespace std;#define Size 1000int main(){ int N1; int table[Size+1]; i...
分类:
其他好文 时间:
2015-07-08 22:07:17
阅读次数:
110
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
For "(()", the longest valid par...
分类:
其他好文 时间:
2015-07-08 19:08:38
阅读次数:
115
题目的意思是:给你一个数N,求由连续的m个素数之和等于N的组数。
这题很简单,一开始没看到题目是连续的素数,所以一开始想用深搜来做,可是不行,后来再看了题目,才知道是连续的素数,是连续的素数就简单很多了。
下面的是 AC的代码:
#include
using namespace std;
int prime[10005];
int main()
{
int i, j, k;
for...
分类:
其他好文 时间:
2015-07-08 14:42:03
阅读次数:
107
想法很直接 复杂度O(mn)class Solution: # @param {string[]} strs # @return {string} def longestCommonPrefix(self, strs): n = len(strs) if...
分类:
其他好文 时间:
2015-07-08 08:14:36
阅读次数:
139
http://acm.hdu.edu.cn/showproblem.php?pid=4055
Problem Description
The signature of a permutation is a string that is computed as follows: for each pair of consecutive elements of the permutat...
分类:
其他好文 时间:
2015-07-07 21:17:12
阅读次数:
367
这道题一开始无从下手,想到找到用hashtable,这样查询没个数是否在List中只需要O(1)时间。以上是第一步, 接下来的想法就比较自然, 将每个数都当成可能的起始点进行测试。待测试的起始点为n,如果n-1在set中,则n必不为起始数字,可以continue优化运行时间代码中使用set来实现ha...
分类:
其他好文 时间:
2015-07-07 10:50:22
阅读次数:
120
题目:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题:
求最大深度 和前面一题类似 用递归遍历就...
分类:
编程语言 时间:
2015-07-06 16:06:14
阅读次数:
143
题意是寻找一个字符串的最大回文字串,最简单的是n3方的算法,由于字符串最大长度为1000,所以这个方法很危险而且不科学。紧接着想到的是一个n方的算法:回文子串是从中间向两边产生的,那么对于每个字符考察这个字符往外的所有可能不就可以找到以这个字符为中心的最长回文子串了吗?当然要考虑偶数的情况,即那个中...
分类:
其他好文 时间:
2015-07-06 15:51:01
阅读次数:
106
wyq说刚入门oi 或是遇到瓶颈的时候就刷DP吧,虽然觉得这么刷CF题有点浪费,但是还是挺爽的,按照solved排序做的,前面的题都挺水的(忘记记录了混蛋),就不写了,从5C开始写解题CF5 C. Longest Regular Bracket Sequence:题目大意,给一个括号序列,让你求最长...
分类:
其他好文 时间:
2015-07-06 15:36:02
阅读次数:
94