码迷,mamicode.com
首页 >  
搜索关键字:k sum    ( 21381个结果
HDU 4981 Goffi and Median(水)
HDU 4981 Goffi and Median 思路:排序就可以得到中间数,然后总和和中间数*n比较一下即可 代码: #include #include #include #include using namespace std; const int N = 1005; int n, a[N], sum; int main() { while (~sca...
分类:其他好文   时间:2014-08-24 23:54:23    阅读次数:288
TYVJ1076
数字三角形2从三角形顶端走到最下面一行所经过数字的和sum mod 100要最大一开始,我就想确定最后的值是最大的关键的地方在哪里,想老久也想不出,觉得这不可能的事情嘛,后来看了题解,原来这是类似于存在性验证的一类DP,即求出0...99哪个结果可能出现,然后取其中的最大值就是结果。设状态vis[i...
分类:其他好文   时间:2014-08-24 23:43:33    阅读次数:211
[LeetCode] Combination Sum (bfs)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeate...
分类:其他好文   时间:2014-08-24 23:34:33    阅读次数:259
TYVJ1305
题解上说这是DP+单调队列优化,我觉得这已经不算是DP了,只算是练习单调队列吧。设dp[i]表示以a[i]结尾的不超过m个的最大的子段和dp[i] = max(sum[i]-sum[i-k])1 2 #include 3 #include 4 #include 5 #define INF 0x...
分类:其他好文   时间:2014-08-24 23:33:43    阅读次数:192
TYVJ1190
新技能get!首先先说一个小模型吧算是,给你n个数,求这n个数能组成的数有哪些(前提n和a[i]不能太大),这n个数的和为sum开一个标记数组vis[i][j]表示前i个数是否可以组成j初始化vis[i][j]为0,vis[i][0]=1(0a[i];for(int i = 1;i=a[i];--j...
分类:其他好文   时间:2014-08-24 23:33:33    阅读次数:186
[LeetCode] Combination Sum II (递归)
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each numb...
分类:其他好文   时间:2014-08-24 23:29:33    阅读次数:176
hdu 1003 Max Sum 简单动态规划
很间的动态规划但ac率低于四分之一了,状态转移方程: dp[i]=max(dp[i-1]+a[i],a[i])注意几点: case 之间有空格 输入的最小负数为-1000 有多组答案找出第一个的意思是,从头便利,得到第一个最大的和就输出被,然后break; /*****************************************************************...
分类:其他好文   时间:2014-08-24 22:20:43    阅读次数:189
Poj 2739 Sum of Consecutive Prime Numbers
1.Linkhttp://poj.org/problem?id=27392.ContentSum of Consecutive Prime NumbersTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 19167Accepted: 1...
分类:其他好文   时间:2014-08-24 20:49:43    阅读次数:186
18.1 不用加号 做加法
先异或求sum,然后求carry,二者的和就是结果,可使还是不能用加号,递归执行,直到b==0。因为每次carry都移位右边多出一个零,然后下一次&的时候必然后面会是0,所以每递归调用一次b后面就多一个零,直到b==0.public class Solution { public static...
分类:其他好文   时间:2014-08-24 20:43:43    阅读次数:259
LeetCode: Sum Root to Leaf Numbers
LeetCode: Sum Root to Leaf NumbersGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is t...
分类:其他好文   时间:2014-08-24 20:41:33    阅读次数:175
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!