码迷,mamicode.com
首页 >  
搜索关键字:two sum    ( 31846个结果
【leetcode刷题笔记】N-Queens
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc...
分类:其他好文   时间:2014-07-18 15:07:26    阅读次数:223
LeetCode "Reorder List"
Not very hard to figure out the solution: splitting the list into 2 halves; reverse the 2nd half and interleave the two halves.But it takes some time ...
分类:其他好文   时间:2014-07-18 14:35:09    阅读次数:214
[ACM] POJ 2442 Sequence (堆的性质)
解题思路:         有m行,每行n个数,从每行中取出一个数相加一起求出sum,这样的sum有n的m次方个。要求的前n个最小的sum值。 第一次使用STL里面的堆,一开始对pop_heap()有点不太理解,后来明白了,比如对数组heap[n],最大下标为n-1建堆,默认的是建立大顶堆,heap[0]是数组中最大的数,写一条pop_heap()语句,就是把heap[0]和 heap[n...
分类:其他好文   时间:2014-07-18 14:11:34    阅读次数:281
CodeForces 425C Sereja and Two Sequences
题意: 两组数字a和b 如果a[i]等于b[j] 则可将a[i]和b[j]前所有数字删掉 这种操作花费e体力 得到1元钱 或者一次删掉所有数字 这种操作花费等于曾经删除的所有数字个数 做完后得到所有钱 问 一共s体力 可以得到多少钱 思路: dp+二分 由数据可知最多拿到300元钱 因此可以定义 dp[i][j]表示有i元钱时 b串删除到了j处时 a串删到的位置 状态转移为 dp[i][j] = lower_bound ( a[j] , dp[i-1][j-1] + 1 ) 意思...
分类:其他好文   时间:2014-07-18 13:27:50    阅读次数:212
动态规划 is beginning。。。。。。。。。
感觉动态规划很模糊,怎么办呢??? 狂刷题吧!!!!!!!!!!!!!!!!!!!!!!!!! 1.POJ 2479 Maximum sum 首刷水题!!!! 双向统计最大和。 AC代码如下: #include #include #include #define inf -1000000000 using namespace std; int main() { int ...
分类:其他好文   时间:2014-07-18 12:37:39    阅读次数:228
POJ 1573 Robot Motion
题意:给你一个棋盘,上面的字母代表机器人要走的方向。如果机器人能走出这个棋盘,则输出机器人所走的步数,否则输出该机器人在走向无限循环前所走的步数,及无限循环所要走的格子数 思路:直接模拟,没有思路(大神可以多考虑些思路) AC代码: #include #include char str[12][12]; int flag[12][12]; int r,c,s,sum,loop; void ...
分类:其他好文   时间:2014-07-18 12:23:10    阅读次数:223
Codeforces Round #256 (Div. 2) B
B. Suffix Structures Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct w...
分类:其他好文   时间:2014-07-18 11:15:25    阅读次数:252
LeetCode :: Sum Root to Leaf Numbers [tree、dfs]
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the to...
分类:其他好文   时间:2014-07-18 11:13:57    阅读次数:204
【leetcode】Combinations
Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],...
分类:其他好文   时间:2014-07-18 09:37:55    阅读次数:161
uva108 Maximum sum(矩阵最大和)
题目;uva108 Maximum sum(矩阵最大和) 题目大意:给出一个n*n的矩阵,求这个矩阵的最大和。这个矩阵不是连通的,只能在这个矩阵内找子矩阵,不能越过边界。 解题思路:枚举起点和终点,每个起点和终点就是一个矩阵,每个矩阵都算矩阵和,然后保留最大值。每个矩阵的值只要横着相加一遍,再竖着相加一遍,就可以得出以这个矩阵为起点的所有的子矩阵的和(这里可以直接要这个矩阵的和...
分类:其他好文   时间:2014-07-17 19:26:05    阅读次数:194
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!