求最大连续子序列一开始想到的一种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
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
题目来源: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
解题思路:
有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
感觉动态规划很模糊,怎么办呢???
狂刷题吧!!!!!!!!!!!!!!!!!!!!!!!!!
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
题意:给你一个棋盘,上面的字母代表机器人要走的方向。如果机器人能走出这个棋盘,则输出机器人所走的步数,否则输出该机器人在走向无限循环前所走的步数,及无限循环所要走的格子数
思路:直接模拟,没有思路(大神可以多考虑些思路)
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
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