自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

  • 博客(545)
  • 收藏
  • 关注

原创 分割成回文需要的最小分割数 Palindrome Partitioning II @LeetCode

两个DP,用DFS肯定通不过。参考:http://yucoding.blogspot.com/2013/08/leetcode-question-133-palindrome.htmlAnalysis:This is a DP problem! Also it is a double DP problem!Why? Because, if we use the same a

2014-01-01 07:42:52 2826

原创 两个字符串交叉得到的字符串 Interleaving String @LeetCode

同 《DP33 两个字符串交叉得到的字符串 Find if a string is interleaved of two other strings @geeksforgeeks》package Level5;/**Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleavi

2014-01-01 04:29:12 2383

原创 最长连续有效括号 Longest Valid Parentheses @LeetCode

思路:用栈保存左括号(遇到(就直接压入栈中。遇到):要用一个变量保存第一个(的下标位置firstLeftPos如果当前栈为空,则更新firstLeftPos,然后忽略这个)。如果栈非空,则弹栈,取出匹配的(。如果弹栈后的栈非空则根据当前)的下标和栈顶元素计算长度;如果弹栈后的栈为空,则更具当前)的下标和firstLeftPos计算长度。package L

2014-01-01 04:04:59 4528 1

原创 判断正则表达式是否匹配 Regular Expression Matching @LeetCode

这道题真心容易错,总的来说思路是递归。判断下一个字符是否是*:如果不是*,则判断当前字符是否匹配。如果是*,则因为不能确定*到底会匹配几个,在当前字符匹配的前提下,要枚举所有的情况,从假设匹配0个,1个,2个。。。只要有一种情况成功了,最终也就成功了。如果是*,但是当前字符不匹配,则跳过两个递归。http://discuss.leetcode.com/questio

2013-12-31 17:13:18 7170

原创 柱状图内最大的矩形面积 Largest Rectangle in Histogram @LeetCode

1 暴力法,TLE2 很巧妙的用了两个stack,一个stack保存高度,另一个保存index遍历height数组,1 如果stack为空或者当前元素的高度大于height stack顶元素(前一个元素)的高度 => 把当前高度额index分别添加到两个stack顶2 如果当前元素的高度等于height stack顶元素的高度 => 什么都不做3 如果当前元素的高度小于heig

2013-12-31 12:52:16 3925

原创 求全是1的最大矩阵面积 Maximal Rectangle @LeetCode

一开始参考http://www.geeksforgeeks.org/maximum-size-sub-matrix-with-all-1s-in-a-binary-matrix/,但发现它的条件是square submatrix,所以本题不符合。后来参考http://yucoding.blogspot.com/2013/01/incomplete-leetcode-question-47-ma

2013-12-31 11:38:32 5049 1

原创 判断是否字符串重组 Scramble String @LeetCode

思路:1 递归:简单的说,就是s1和s2是scramble的话,那么必然存在一个在s1上的长度l1,将s1分成s11和s12两段,同样有s21和s22。那么要么s11和s21是scramble的并且s12和s22是scramble的;要么s11和s22是scramble的并且s12和s21是scramble的。如果要能通过OJ,还必须把字符串排序后进行剪枝http://

2013-12-31 08:18:47 14621 2

原创 DP36 如何切出最大长度乘积 Maximum Product Cutting @geeksforgeeks

Given a rope of length n meters, cut the rope in different parts of integer lengths in a way that maximizes product of lengths of all parts. You must make at least one cut. Assume that the length of r

2013-12-30 07:17:43 2719

原创 DP35 最长等差数列 Longest Arithmetic Progression @geeksforgeeks

在一个有序数组里找等差数列,用3个指针,以中间指针为基准,移动前后指针。Given a set of numbers, find the Length of the Longest Arithmetic Progression (LLAP) in it.Examples:set[] = {1, 7, 10, 15, 27, 29}output = 3The lo

2013-12-30 06:59:32 2095

原创 DP34 流水线调度问题 Assembly Line Scheduling @geeksforgeeks

A car factory has two assembly lines, each with n stations. A station is denoted by Si,j where i is either 1 or 2 and indicates the assembly line the station is on, and j indicates the number of the s

2013-12-30 05:58:25 3197

原创 DP33 两个字符串交叉得到的字符串 Find if a string is interleaved of two other strings @geeksforgeeks

Given three strings A, B and C. Write a function that checks whether C is an interleaving of A and B. C is said to be interleaving A and B, if it contains all characters of A and B and order of all

2013-12-30 03:37:41 1962

原创 DP32 单词按照字典分割问题 Word Break Problem @geeksforgeeks

Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words. See following examples for more details.This is a

2013-12-30 01:11:39 2115

原创 DP31 取大小游戏中的最优策略(附:如何对DP[0][n]进行对角线递推) Optimal Strategy for a Game @geeksforgeeks

Problem statement: Consider a row of n coins of values v1 . . . vn, where n is even. We play a game against an opponent by alternating turns. In each turn, a player selects either the first or last co

2013-12-29 13:23:48 1956

原创 DP30 求骰子能凑成给定和的组合数 Dice Throw @geeksforgeeks

Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of values on each face when all the dice are thrown.The Naive approach is to find all

2013-12-29 04:24:27 4413

原创 DP29 最长相同子串 Longest Common Substring @geeksforgeeks

Given two strings ‘X’ and ‘Y’, find the length of the longest common substring. For example, if the given strings are “GeeksforGeeks” and “GeeksQuiz”, the output should be 5 as longest common substrin

2013-12-29 03:30:59 1881

原创 DP28 求能变成回文的最小插入字符个数 Minimum insertions to form a palindrome @geeksforgeeks

Given a string, find the minimum number of characters to be inserted to convert it to palindrome.Before we go further, let us understand with few examples:    ab: Number of insertions required i

2013-12-29 02:59:43 1670

原创 DP27 2D矩阵中最大的矩形和 Maximum sum rectangle in a 2D matrix @geeksforgeeks

Given a 2D array, find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with blue rectangle and sum of this subarray is 29.This p

2013-12-29 01:46:56 2901

原创 DP26树的最大独立子集问题 Largest Independent Set Problem @geeksforgeeks

Given a Binary Tree, find size of the Largest Independent Set(LIS) in it. A subset of all tree nodes is an independent set if there is no edge between any two nodes of the subset.For example, consid

2013-12-29 00:27:29 2324

原创 DP25 子集和问题 Subset Sum Problem @geeksforgeeks

同分割区间问题:http://blog.csdn.net/fightforyourdream/article/details/17602699Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to give

2013-12-28 06:35:50 2409

原创 DP24 最优BST Optimal Binary Search Tree @geeksforgeeks

Given a sorted array keys[0.. n-1] of search keys and an array freq[0.. n-1] of frequency counts, wherefreq[i] is the number of searches to keys[i]. Construct a binary search tree of all keys such tha

2013-12-28 06:05:29 2525

原创 DP23 Bellman–Ford Algorithm @geeksforgeeks

Given a graph and a source vertex src in graph, find shortest paths from src to all vertices in the given graph. The graph may contain negative weight edges.We have discussed Dijkstra’s algorithm fo

2013-12-28 04:57:56 2708

原创 DP22 堆盒子问题 Box Stacking Problem @geeksforgeeks

You are given a set of n types of rectangular 3-D boxes, where the i^th box has height h(i), width w(i) and depth d(i) (all real numbers). You want to create a stack of boxes which is as tall as possi

2013-12-28 03:19:33 3272

原创 DP21 LIS的变种问题-建桥问题 Variations of LIS-Building Bridge @geeksforgeeks

We have discussed Dynamic Programming solution for Longest Increasing Subsequence problem inthis post and a O(nLogn) solution in this post. Following are commonly asked variations of the standard LI

2013-12-28 02:23:47 2046

转载 Debian普通用户添加sudo权限

刚安装好的Debian默认还没有sudo功能。1、安装sudo# apt-get install sudo2、修改 /etc/sudoers 文件属性为可写# chmod +w /etc/sudoers3、编辑 /etc/sudoers ,添加如下行# vim /etc/sudoersroot ALL=(ALL) ALLuser ALL=(ALL) ALL 用户us

2013-12-27 13:06:12 4410

转载 Kill Process in Linux or Terminate a Process in UNIX / Linux Systems

Iam a new Linux system user. How do I kill process on Linux based server using command line options? How can I kill running process on Unix?Linux and Unix-like operating system come with the kil

2013-12-27 12:27:04 1853

转载 修改 Ubuntu 用户的 Shell

最近我写了一个申请开发空间的程序, 可以自动生成支持 PHP, Python (Django) 等开发环境, 也提供 SSH 的访问方式. 今天有同事反馈说 Shell 用不了 ll 命令, 也不能 tab 补全, 无比蛋疼.因为使用 useradd 添加用户时, 默认配给用户的是最原始的 sh 而不是常用的 bash, 所以很多命令都不能使用, 下面提供相关的修改方法.修

2013-12-27 12:25:44 4720

原创 DP20 求pair的最大长度链 Maximum Length Chain of Pairs @geeksforgeeks

是LIS的变型题,如果遇到两维则先排序一维再对另一维动态规划You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. C

2013-12-27 09:33:16 1553

原创 DP19 自动换行问题 Word Wrap Problem @geeksforgeeks

挺复杂的一题,用了多个dp数组来保存过程量Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines ar

2013-12-27 07:34:51 2274

原创 DP18 分割区间问题 Partition problem @geeksforgeeks

思路:把能否划分区间的问题转化为能不能找到一个使得和为总和的一半的子区间,然后转为01背包问题,分析每一个元素是否取Partition problem is to determine whether a given set can be partitioned into two subsets such that the sum of elements in both subsets

2013-12-27 04:44:06 2274

原创 DP17 最少回文切割次数 Palindrome Partitioning @geeksforgeeks

Given a string, a partitioning of the string is a palindrome partitioning if every substring of the partition is a palindrome. For example, “aba|b|bbabb|a|b|aba” is a palindrome partitioning of “ababb

2013-12-27 03:55:35 1935

原创 DP16 Floyd Warshall Algorithm @geeksforgeeks

The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of vertices in a given edge weighted directed Graph.

2013-12-27 03:07:16 1477

原创 DP11 高楼扔鸡蛋问题 Egg Dropping Puzzle @geeksforgeeks

package DP;/** * 100层楼,两个鸡蛋。某层之上扔鸡蛋就会碎。问至少要测试多少次才能找出这层楼来 * 我们可以决定怎么扔(min),但必须假设我们的运气最差(max) * * 100层楼,两个鸡蛋。某层之上扔鸡蛋就会碎。问至少要测试多少次才能找出这层楼来?思路:首先要理解清楚题意,本题不是要找在哪一层以上会把鸡蛋扔破!而是我们假设在W层以上会把鸡蛋仍破,现在问

2013-12-26 02:18:50 1489

原创 DP10 0-1背包问题 0-1 Knapsack Problem @geeksforgeeks

01背包问题的取和不取实际上就是一个机会成本的问题,如果取了某件东西,尽管当前的价值暂时地增加了,但你付出了机会成本。因为如果不取,留下的空间以后说不定可以放更有价值的东西。因此空间和价值总是一对矛盾。我们的目的是要用有限的空间装入最优价值的东西。Given weights and values of n items, put these items in a knapsack

2013-12-25 06:19:48 1689

原创 DP9 二项式系数 Binomial Coefficient @geeksforgeeks

Following are common definition of Binomial Coefficients.1) A binomial coefficient C(n, k) can be defined as the coefficient of X^k in the expansion of (1 + X)^n.2) A binomial coefficient C(n, k

2013-12-25 05:38:42 1446

原创 DP8 矩阵链相乘 Matrix Chain Multiplication @geeksforgeeks

思路是在矩阵链的每一个地方分别分开,然后找最小Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is not actually to perform the multiplications, but merely to deci

2013-12-25 05:24:11 1698

原创 DP7 两道换硬币的问题 Coin Change @geeksforgeeks

1 Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn’t m

2013-12-25 04:38:39 2527

转载 老鸟的Python入门教程

重要说明这不是给编程新手准备的教程,如果您入行编程不久,或者还没有使用过1到2门编程语言,请移步!这是有一定编程经验的人准备的.最好是熟知Java或C,懂得命令行,Shell等.总之,这是面向老鸟的,让老鸟快速上手Python教程.为什么总结这样的一个教程我虽不是老鸟,但已熟悉Java,C/C++, Shell和Perl,且对常见的数据结构和算法等都了解.最近因项目需要,要做一个小工具

2013-12-24 11:52:51 1492

原创 DP6 最小路径花费 Min Cost Path @geeksforgeeks

Dynamic Programming | Set 6 (Min Cost Path)Given a cost matrix cost[][] and a position (m, n) in cost[][], write a function that returns cost of minimum cost path to reach (m, n) from (0, 0)

2013-12-24 02:19:41 1828

原创 DP5 编辑距离 Edit Distance @geeksforgeeks

Problem: Given two strings of size m, n and set of operations replace (R), insert (I) and delete (D) all at equal cost. Find minimum number of edits (operations) required to convert one string into an

2013-12-24 01:03:49 1565

原创 DP4 最长公共子序列 LCS @geeksforgeeks

LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in the same relative order, but not necessarily con

2013-12-24 00:36:58 1589

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除