poj----Maximum sum(poj 2479)】的更多相关文章

d(A) = max{sum(a[s1]..a[t1]) + sum(a[s2]..a[t2]) | 1<=s1<=t1<s2<=t2<=n} 即求两个子序列和的和的最大值. 为单个区间子序列和的最大值的变形. 左边的从左向右扫描,而右边的从右向左扫描即可. #include<cstdio> #include<algorithm> using namespace std; const int MAXN=50000+10; int left[MAXN],…
Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40596   Accepted: 12663 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…
题目链接:http://poj.org/problem?id=2479 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; int dp1[maxn]; int dp2[maxn]; int a[maxn]; int N; int main() { int T;…
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…
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 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30704   Accepted: 9408 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 of…
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representati…
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> #include <vector> #include <cmath> #define nmax 10005 using namespace std; int prime[nmax],n; vector<int> vprime; void init() { memset(pri…
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然后问你这个数x有多少种方式能由连续的素数相加得来? 分析: 首先用素数筛选法把10000以内的素数都找出来按从小到大保存到prime数组中. 然后找到数X在prime中的上界, 假设存在连续的素数之和==X, 那么一定是从一个比X小的素数開始求和(不会超过X的上界),直到和sum的值>=X为止. 所…
Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33918   Accepted: 10504 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…
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…
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).   也就是说求最大的子段和…
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…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=44  Maximum Sum  Background A problem that is simple to solve in one dimension is often much more difficult to solve in more th…
题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN][MAXN]; int dp[…
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…
1146. Maximum Sum Time limit: 1.0 second Memory 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…
题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行处理,也是,通过补全一个相同的,问题就迎刃而解了,所以把n*n的矩阵扩展成2n*2n的矩阵就好了. #include <cstdio> #include <cstring> #define MAXN 160 int a[MAXN][MAXN], sum[MAXN][MAXN]; int…
Given an array of n elements.Find the maximum sum when the array elements will be arranged in such way. Multiply the elements of each pair and add to get maximum Sum. Sum could be larger so take mod with 10^9+7. Example1: Input: n= -,,,,-,-, Output:…
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the starting p…
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the starting p…
Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array.  (Formally, C[i] = A[i]when 0 <= i < A.lengt…
Given an array A of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths L and M.  (For clarification, the L-length subarray could occur before or after the M-length subarray.) Fo…
Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array.  (Formally, C[i] = A[i] when 0 <= i < A.leng…
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the starting p…
Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array.  (Formally, C[i] = A[i] when 0 <= i < A.leng…
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the starting p…
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 representation of xx , for example, S(123)=1+2+3=6S(123)=1+2+3=6 , S(0)=0S(0)=0 . Your task is to find two integers a,ba,b , such that 0≤a,b≤n0≤a,b≤n ,…
[抄题]: In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the star…
B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output You are given a positive integer nn. Let S(x)S(x) be sum of digits in base 10 representation of xx, for example, S(…