码迷,mamicode.com
首页 >  
搜索关键字:combination sum    ( 21657个结果
[leetcode]Sum Root to Leaf Numbers @ Python
原题地址:http://oj.leetcode.com/problems/sum-root-to-leaf-numbers/题意:Given a binary tree containing digits from0-9only, each root-to-leaf path could repre...
分类:编程语言   时间:2014-05-12 01:28:30    阅读次数:440
UVA 1362 - Exploring Pyramids(计数问题+区间DP)
题目链接:1362 - Exploring Pyramids 白书上的例题,思路是对于每个结点,往后遍历分为左右两边子树来考虑,左边的子树为去掉根节点剩下的子树,而右边是要算上根节点的,这样就不会有重复的情况出现,然后根据乘法原理,左右两边情况相乘为总情况数,然后计算这些总和。  f[i][j]表示[i,j]结点的情况种数,那么 f[i][j] = sum{f[i + 1][k - 1] * ...
分类:其他好文   时间:2014-05-11 07:02:11    阅读次数:277
UVA 11361 - Investigating Div-Sum Property(数位DP)
题目链接:11361 - Investigating Div-Sum Property 白书上的例题,不过没有代码,正好前几天写了一题数位DP的题目,这题也就相对轻松了。 dp[i][x][y]表示加到第i位,数字 % k,数位和 % k的组合情况数,那么现在要添加一个0 - 9的数字上去状态转移为 dp[i + 1][(x * 10 + num) % k][(y + num) % k],计...
分类:其他好文   时间:2014-05-11 05:23:33    阅读次数:316
[LeetCode]Binary Tree Maximum Path Sum, 解题报告
题目 Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree,...
分类:其他好文   时间:2014-05-11 03:25:24    阅读次数:298
nylg 640 Geometric Sum
Geometric Sum时间限制:1000ms | 内存限制:65535KB难度:3描述Compute (a + a^2 + … + a^n) mod m.(a+a2+…an)mod输入Three integers a,n,m.(1≤a,n,m≤10^18)It ends with EOF.输出T...
分类:其他好文   时间:2014-05-10 05:01:02    阅读次数:339
Large sum
聪明的办法是想:求前10位,那只要前8位加起来,进2位就OK。本的办法,就是真的加起来,截前面10位。如我。numList = str.split()sum = 0for i in range(0,len(numList)): sum += int(numList[i][0:50]) p...
分类:其他好文   时间:2014-05-09 23:16:32    阅读次数:350
USACO/fence8 迭代加深搜索+剪枝
题目链接 迭代加深搜索思想。 枚举答案K,考虑到能否切出K个木头,那么我们当然选最小的K个来切。 1、对于原材料,我们是首选最大的还是最小的?显然,首选大的能够更容易切出,也更容易得到答案。 2、对于目标木头,我们是优先得到最大的还是最小的?显然,由于K个木头我们都要得到,那么当然先把最大的(最难得到的)先得到,这种搜索策略更优。 3、假设总原材料为all,前K个木头总和为sum,那...
分类:其他好文   时间:2014-05-09 21:07:28    阅读次数:305
Summation of primes
是我算法不对,还是笔记本CPU太差?我优化了两次,还是花了三四个小时来得到结果。在输出上加1就是最终结果。The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two mil...
分类:其他好文   时间:2014-05-09 16:20:08    阅读次数:295
Leetcode | Path Sum I && II
Path Sum IGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the gi...
分类:其他好文   时间:2014-05-09 13:21:59    阅读次数:320
杭电oj 1001
#includeusing namespace std;int main(){ int n = 0, sum; while (cin>>n) { sum = 0; // 这里要清零 for (int i =0; i <= n; i++) {...
分类:其他好文   时间:2014-05-09 05:38:17    阅读次数:241
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!