码迷,mamicode.com
首页 >  
搜索关键字:two sum    ( 31846个结果
Problem Path Sum II
Problem Description:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.Solution: 递归。 1 public List>...
分类:其他好文   时间:2014-07-07 16:59:12    阅读次数:169
Topcoder SRM 626 DIV2 SumOfPower
本题就是求所有连续子数列的和开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列循环遍历即可 int findSum(vector array) { int sum = 0; for(int i = 0 ; i < array.size(); ++...
分类:其他好文   时间:2014-07-07 16:10:42    阅读次数:179
Minimum Path Sum
题目 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down...
分类:其他好文   时间:2014-06-30 11:10:34    阅读次数:211
Codeforces 14D Two Paths 树的直径
题目链接:点击打开链接 题意:给定一棵树 找2条点不重复的路径,使得两路径的长度乘积最大 思路: 1、为了保证点不重复,在图中删去一条边,枚举这条删边 2、这样得到了2个树,在各自的树中找最长链,即树的直径,然后相乘即可 #include #include #include #include #include #include #include #include #include #i...
分类:其他好文   时间:2014-06-30 07:30:01    阅读次数:235
Median of Two Sorted Arrays
题目 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 方法 转换为寻找第k大的数。 ...
分类:其他好文   时间:2014-06-30 06:05:58    阅读次数:261
Edit Distance
题目 Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitte...
分类:其他好文   时间:2014-06-30 00:46:38    阅读次数:262
N-Queens
题目 The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-que...
分类:其他好文   时间:2014-06-30 00:34:18    阅读次数:188
Structure and Interpretation of Computer Programs-Exercise 1.3
【问题】 Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. 定义一个过程,它以三个数为参数,返回其中较大的两个数的平方和。 【普通版】 (define (sum-square-largest x y ...
分类:其他好文   时间:2014-06-30 00:19:52    阅读次数:270
USACO nocows DP
这题没想出来,直接参考了nocow,太弱了= =。 基本思想是动态规划,因为树是递归结构,所以可以递归分成子问题处理。一个树可以看成根加左子树加右子树,所以根据乘法原理,N个节点放成k层的结构等于i个节点放成k - 1层乘以N - i - 1个节点放在k - 1层的积。 令dp[i][j] 为i个节点放j层的最多可能数量,则dp[i][j] = sum{dp[k][j - 1] * dp[i ...
分类:其他好文   时间:2014-06-29 23:49:12    阅读次数:339
Scramble String
题目 Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great /...
分类:其他好文   时间:2014-06-29 23:16:19    阅读次数:312
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!