http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=1000 求最大连续子段和及其起始位置和终止位置,很基础的动态规划(DP)问题,看完DP第一次做的DP题目 DP真的是一种很优美的算法,或者说思想,但是比较难理解,我对DP的理解还很浅薄 # include <stdio.h> # define INF 1000000000 int main() { i
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 292444 Accepted Submission(s): 69379 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) 问题描述 Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For e
题目描述 给出一个长度为 n 的序列,要求支持如下两种操作: A l r x :将 [l,r] 区间内的所有数加上 x : Q l r : 询问 [l,r] 区间的最大连续子段和. 其中,一个区间的最大连续子段和指的是:该区间所有子区间的区间和中的最大值(本题中子区间包括空区间,区间和为 0 ). 输入 第一行两个整数 n.m,表示序列的长度以及操作的数目. 之后的 m 行,每行输入一个操作,含义如题目所述.保证操作为 A l r x 或 Q l r 之一. 对于 3
http://www.itint5.com/oj/#9 一开始有了个n*n的算法,就是把原来的数组*2,由环形的展开成数组.然后调用n次最大子段和的方法.超时. 后来看到个O(n)的算法,就是如果不跨越末尾,就是最大字段和:如果跨越末尾,就是sum-(最小子段和)http://blog.csdn.net/hackbuteer1/article/details/6694193 int maxConsSum2(const vector<int> &arr) { if (arr.size()
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14601 Accepted: 4720 Description Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each field contains a certain number of cows, 1 <= ncows <= 2
You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }. Given M queries, your program must output the results of these queries. Inp