码迷,mamicode.com
首页 >  
搜索关键字:two sum    ( 31846个结果
Cracking the Coding Interview Q1.8
Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a ...
分类:其他好文   时间:2014-07-08 21:44:23    阅读次数:177
线段树ADT
线段树应用: 有一个数列,初始时为 a1,a2,… aN (N 1)  将 ai 的值加上 val ; 2)  对于一个区间[l,r],该区间的和。 3)  对于一个区间[l,r],求该区间的最大值。 数据结构: //Node Type struct Node{ int left, right; int max, sum; } tree[maxn]; /* tree[k]'...
分类:其他好文   时间:2014-07-08 21:31:33    阅读次数:237
HDU--Max sum---DP练习
Max Sum Time Limit: 2000ms   Memory limit: 32768K  有疑问?点这里^_^ 题目描述 Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-...
分类:其他好文   时间:2014-07-08 21:30:17    阅读次数:205
POJ-1475-Pushing Boxes(BFS)
Description Imagine you are standing inside a two-dimensional maze composed of square cells which may or may not be filled with rock. You can move north, south, east or west one cell at a step. T...
分类:其他好文   时间:2014-07-08 21:04:29    阅读次数:347
POJ 3093 Margaritas on the River Walk (0-1背包变形)
这题目的思路很巧妙,什么情况下剩下的所有物品都放不下呢?就是当前剩余物品中最小的那个也放不下。所以,先把物品按照容量从小到大排序,依次枚举当前背包为放不下的最小物品的情况。 对于当前物品i,必有1到i-1的所有物品都放进去,这时候比i大的物品谁放谁不放是不确定的。转换成0-1背包问题:把前i-1个物品都放进去以后,得到空间为tsum - sum[i-1](前缀和)的包,只要从第i+1到第n个物品...
分类:其他好文   时间:2014-07-08 19:47:17    阅读次数:187
hdu 1588 Gauss Fibonacci(矩阵嵌矩阵)
题目大意: 求出斐波那契中的 第 k*i+b 项的和。 思路分析: 定义斐波那契数列的矩阵 f(n)为斐波那契第n项 F(n) = f(n+1)    f(n) 那么可以知道矩阵 A = 1 1        1  0 使得 F(n) = A * F(n+1) 然后我们化简最后的答案 sum = F(b) +   F(K+b) +  F (2*k +...
分类:其他好文   时间:2014-07-08 14:47:19    阅读次数:162
一步一步挖出Compute
前几天在做结账的时候,对数据表DataGridView控件的单列求和纠结了一番。        现在几乎养成了习惯,对于一些东西疏于开始的思考,不会先想到百度,这里我是先想到了第一版的机房收费那块的结账求和:        截取了充值金额片段,代码如下:        '读取充值金额 strSQL = "select sum(addmoney) as AddCash from Re...
分类:其他好文   时间:2014-07-08 14:31:33    阅读次数:160
Cracking the Coding Interview Q2.5
You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s ...
分类:其他好文   时间:2014-07-08 13:34:40    阅读次数:195
POJ1753:Flip Game
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29713   Accepted: 12876 Description Flip game is played on a rectangular 4x4 field with two-sided...
分类:其他好文   时间:2014-07-08 13:32:49    阅读次数:189
HDU 4587 TWO NODES (双连通割点应用)
题意:N个点(0~n-1),M条无向边,问去掉2个点后最多的连通分块有多少。 先去掉一个点求出各个割点,并在dfs过程中求出去掉这个割点有多少个连通分块(将iscut[u]=true改为iscut[u]++), 这样子第二次就可以直接找出最多的连通分块了。 #include #include #include #include #include #include #inclu...
分类:其他好文   时间:2014-07-08 13:06:23    阅读次数:145
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!