杭电 1003 Max Sum (动态规划)】的更多相关文章

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max来存放找到的子序列的和中的最大值,通过不断比较,对max的值进行更新,最后我们就能够得到最大子序列的和,于是很容易想到用暴力搜索,见上一篇博客,这样的时间复杂度为O(n^3),是超时的. 又因为想到只要一个数不是负数,不管它再小,加上去也是会使和变大的,所以我们需要用另一个变量来判断即将要加上的一个…
这一题目是要求连续子序列的最大和,所以在看到题目的一瞬间就想到的是把所有情况列举出来,再两个两个的比较,取最大的(即为更新最大值的意思),这样的思路很简单,但是会超时,时间复杂度为O(n^3),因为有三重for语句 #include<stdio.h> #define maxn 101000 int main() { int ncase,flag=1,n,max,sum=0,h,z,a[maxn]; long i,j,k; scanf("%d",&ncase); wh…
参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; int a[N],dp[N]; int n; void test() { cout<<"\n---------\n"; ;i<=n;i++) { cout<<'[…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 330535    Accepted Submission(s): 78678 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input contains…
解题思路: 本题在给定的集合中找到最大的子集合[子集合:集合的元素的总和,是所有子集合中的最大解.] 结果输出: 最大的子集合的所有元素的和,子集合在集合中的范围区间. 依次对元素相加,存到一个 sum 中,同时ans=sum;定义左右边界 left,right;临时左边界ll=1; 如果sum>ans,则ans=sum; 左边界 left=tem; right=i+1; 如果sum<0,则sum=0; tem=i+2; Ac code: #include<bits/stdc++.h&g…
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum表示当前子段和,maxsum表示最大子段和.不妨设想:当sum为负数的时候: 1.当下一个数字a[i]为正数的时候,sum+a[i] < a[i],不如将sum归零重新计算 2.当下一个数字为负数的时候,sum+a[i]< 0 ,若再下一个数字还为负数,依旧可以得出和小于零--直到遇到一个正数,此…
HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义dp[i]表示以a[i]为结尾的子序列的和的最大值,因而最大连续子序列及为dp数组中的最大值.   状态转移方程:dp[1] = a[1]; //以a[1]为结尾的子序列只有a[1]:  i >= 2时, dp[i] = max( dp[i-1]+a[i],  a[i] ); dp[i-1]+a[i…
题目链接: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)Total Submission(s): 158421    Accepted Submission(s): 37055 Problem Description Given a sequence a[1],a[2]…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 250714    Accepted Submission(s): 59365 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
转载于acm之家http://www.acmerblog.com/hdu-1003-Max-Sum-1258.html Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 242353    Accepted Submission(s): 57218 Problem Description Given a sequence…
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i]=max(dp[i]+a[i],a[i]) 解释: 以a[i]结尾的最大值,要么是以a[i-1]为结尾的最大值+a[i],要么是a[i]自己本身,就是说,要么是连同之前的 构成一个多项的字串,要么自己单独作为一个字串,不会有其他的可能了. 状态规划的对状态的要求是:当前状态只与之前的状态有关,而且不影响下一…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 211310    Accepted Submission(s): 49611 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 193355 Accepted Submission(s): 45045 Problem Description Given a sequence a[1],a[2],a[3]--a[n], your job is to calculate the max sum of a su…
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给你一串数列,让你求出其中 一段连续的子数列 并且 该子数列所有数字之和最大,输出该子数列的和.起点与终点序号. 具体细节不再赘述,看原题就好了. 说实话我觉得这个题有点难...想了好久,智商不够... 但实际的代码还算是相当简单的,主要的逻辑就在中间那两个 if 里了,仔细看看就能理解了. #include<stdio.h> #include<string.h> int main() {…
今天看了一上午dp.看不太懂啊.dp确实不简单.今天開始学习dp,搜了杭电的dp46道,慢慢来吧.白书上的写的 又不太具体,先写几道题目再说. .. 题目连接:id=516&page=1">点击打开链接 思路:就是当当前的和是小于0的时候就又一次计数.大于或者等于0的时候都相加... id=516&page=1">代码: /* Name: Copyright: Author: Date: 08/08/15 08:41 Description: */ #inc…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the m…
题目大意:求一串数字中,几个连续数字加起来最大值,并确定起始和最末的位置. 思路:这是一题DP题,但是可以用尺取法来做.我一开始不会,也是看了某大神的代码,然后有人告诉我这是尺取法,现在会了. //尺取法 #include<stdio.h> #include<string.h> ]; main() { int t,flag; scanf("%d",&t); flag=t; while(t--) { memset(que,,sizeof(que)); ;…
#include <stdio.h> int main(){ int i,t,j,n,x; int start,end,temp,max,sum; scanf("%d",&t); ;i<t;i++){ temp=; max=-; sum=; scanf("%d",&n); ;j<n;j++){ scanf("%d",&x); sum+=x; if(sum>=max){ max=sum; sta…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 154155    Accepted Submission(s): 35958 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.   Input The first line of the input contai…
点我看题目 题意 : 就是让你从一个数列中找连续的数字要求他们的和最大. 思路 : 往前加然后再判断一下就行. #include <iostream> #include<stdio.h> using namespace std; int main() { int n,start,end; cin>>n; int m ; ; k <= n ; k++) { cin>>m; ,sum = ,flag = ; ; i <= m- ; i++) { in…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 135262    Accepted Submission(s): 31311 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input contains…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 294096    Accepted Submission(s): 69830 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 72615    Accepted Submission(s): 16626 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 141547    Accepted Submission(s): 32929 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 237978    Accepted Submission(s): 56166 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 252815    Accepted Submission(s): 59950 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su…
原创 http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目要求求出一个序列里面的最大序列和,序列要求是连续的,给出最大序列和,序列首元素下标和尾元素下标,按特定的格式输出. 解题思路: 动态规划,我们可以将所有序列按以序列中的元素a[i](i=1~n)结尾进行分类,比如: 以a[1]结尾的序列有:a[1] 以a[2]结尾的序列有:a[1]a[2],a[2] 以a[3]结尾的序列有:a[1]a[2]a[3],a[2][3],a[3] ......  这…