求最大连续子序列一开始想到的一种O(n^2)的算法,应该会超时运用动态规划的思想,想出了下面的方法#include using namespace std;struct DP{ int sum,sta,end; void init(int su,int st,int en){ sum=su; sta...
分类:
其他好文 时间:
2014-07-19 18:04:36
阅读次数:
230
止乎于分享!IDCode18 = { validate: function (value) { if (value.length != 18) return false; var value = value.toLowerCase(); var sum...
分类:
其他好文 时间:
2014-07-19 16:24:38
阅读次数:
230
class Solution {public: int maxSubArray(int A[], int n) { int cur_sum = 0; int max_sum = INT_MIN; for (int i=0; i max_...
分类:
其他好文 时间:
2014-07-19 15:18:15
阅读次数:
160
1877. Bicycle CodesTime limit: 0.5 secondMemory limit: 64 MBDen has two four-digit combination locks for protecting his bicycle from thieves. Every ev...
分类:
其他好文 时间:
2014-07-19 15:02:20
阅读次数:
313
Description 给出3*n个数xi,要求构造三个长度为n的序列ai,bi,ci,使得满足下列条件: 1到3*n的每个数都在三个序列中的某个出现一次且仅一次; S=sum((x[ai]-x[bi])*x[ci])最大。 输出最大的S。多组数据。Input Format 第一行...
分类:
其他好文 时间:
2014-07-19 14:39:18
阅读次数:
214
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep...
分类:
其他好文 时间:
2014-07-18 20:09:38
阅读次数:
433
Given 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 given sum.Fo...
分类:
其他好文 时间:
2014-07-18 18:28:44
阅读次数:
231
此题就是在01背包问题的基础上求所能获得的第K大的价值。
具体做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,其实就是2个数组合并之后排序,但是实际做法最好不要怎么做,因为你不知道总共有多少种,而我们最多只需要前K个大的就行了(因为可能2个数组加起来的组合数达不到K个),如果全部加起来数组开多大不清楚,所以可以选用...
分类:
其他好文 时间:
2014-07-18 18:14:27
阅读次数:
224
题目来源:HDU 3047 Zjnu Stadium
题意:给你一些人 然后每次输入a b c 表示b在距离a的右边c处 求有多少个矛盾的情况
思路:用sum[a] 代表a点距离根的距离 每次合并时如果根一样 判断sum数组是否符合情况 根不一样 合并两棵树 这里就是带权并查集的精髓
sum[y] = sum[a]-sum[b]+x 这里y的没有合并前b的根
#include
#in...
分类:
其他好文 时间:
2014-07-18 18:06:11
阅读次数:
264
题目:如果整数A的全部因子(包括1,不包括A本身)之和等于B,并且整数B的全部因子(包括1,不包括B本身)之和等于A,,则称整数A和B为亲密数。求解3000以内的全部亲密数。#include #include int factor_sum(int n) // 计算n的因子和{ int i; ...
分类:
其他好文 时间:
2014-07-18 17:32:55
阅读次数:
216