POJ2479 Maximum sum[DP|最大子段和]】的更多相关文章

Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Description Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below: Your task is to calculate d(A). Input The input consists o…
题目链接. 分析: 用 d1[i] 表示左向右从0到i的最大连续和,d2[i] 表示从右向左, 即从n-1到i 的最大连续和. ans = max(ans, d1[i]+d2[i+1]), i=0,1, 2,...,n-2 直接枚举会TLE, 优化下就可AC. #include <iostream> #include <cstdio> #include <cstdlib> #include <string> #include <algorithm>…
http://poj.org/problem?id=2479 题目大意:给定一组n个整数:a ={a1, a2,…,我们定义一个函数d(a)如下: 你的任务是计算d(A).输入由T(<=30)测试用例组成.在输入的第一行中给出了测试用例(T)的数量. 每个测试用例包含两行.第一行是一个整数n(2<=n<=50000).第二行包含n个整数:a1, a2,…,an. ( | ai |  < = 10000).为每个测试用例打印一行.该行应该包含整数d(A).   也就是说求最大的子段和…
最大子序列和的加强版. 借助最大子序列和,分别正向和反向遍历一遍得到left和right数组(具体含义见代码注释) 然后再对left和right数组进行修正,保存从对应元素起向左或向右的最大连续和. 最后再次遍历一遍得到最大的ans. AC代码如下: #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; ; int left…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 677    Accepted Submission(s): 358 Problem Description There is a number sequence A1,A2...…
Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36100   Accepted: 11213 Description Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below: tex=d%28A%29%3D%5Cmax_%7B1%5Cleq+s_1%5Cleq+t_1%3Cs_2%5Cleq…
Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转换成最大字段和的问题. 压缩行或者列都是能够的. int n, m, x, y, T, t; int Map[1010][1010]; int main() { while(~scanf("%d", &n)) { memset(Map, 0, sizeof(Map)); for(i…
Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44459   Accepted: 13794 Description Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below: Your task is to calculate d(A). Input The input consists o…
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this p…
题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN][MAXN]; int dp[…