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

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…
解题思路: 本题在给定的集合中找到最大的子集合[子集合:集合的元素的总和,是所有子集合中的最大解.] 结果输出: 最大的子集合的所有元素的和,子集合在集合中的范围区间. 依次对元素相加,存到一个 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): 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) 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…
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): 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…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1003 题意 给出一个序列 要求找出一个和最大的子序列 思路 O(N)的做法 但是要标记 子序列的头部位置 如果输入全部是负数的话 应该输出是最小的负数和它的位置 而不是输出0 0 0 AC代码 #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<c…
今天看了一上午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…
这是一道DP入门题目,知识点是“最大连续子序列” 题目大意:给你一个长度为n的数字序列,取其中一段连续的序列,要求和最大: 分析:这是一道裸题,没有什么花里胡哨的东西,主要是写出状态转移方程 dp[i] = max{dp[i-1] + A[i], A[i]};  dp[i]是以i位置为结尾位置的最优解.  对于i位置上的A[i],一定对dp[i]做出了贡献. 对于i以前的位置,他们的最优解是dp[i-1],当dp[i-1]>=0时,dp[i-1]对dp[i]做出了贡献;反之,dp[i-1]对dp…
HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given…
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值,其中第i个子序列包括a[j], 则max(dp[m][k]),m<=k<=n 即为所求的结果 <2>初始状态: dp[i][0] = 0, dp[0][j] = 0; <3>状态转移: 决策:a[j]自己成为一个子段,还是接在前面一个子段的后面 方程: a[j]直接接在前面…
虽然这道题看起来和 HDU 1024  Max Sum Plus Plus 看起来很像,可是感觉这道题比1024要简单一些 前面WA了几次,因为我开始把dp[22][maxn]写成dp[maxn][22]了,Orz 看来数组越界不一定会导致程序崩溃,也有可能返回一个错误的结果 dp[i][j]表示前j个数构成前i段所得到的最大值 状态转移方程: dp[i][j] = max{dp[i][j-1],  dp[i-1][j-len[i]] + sum[j] - sum[j-len[i]]} 分别对应…
题目链接:hdu 3415 Max Sum of Max-K-sub-sequence 题意: 给你一串形成环的数,让你找一段长度不大于k的子段使得和最大. 题解: 我们先把头和尾拼起来,令前i个数的和为sum[i]. 然后问题变成了求一个max{sum[i]-sum[j]}(i-k<j<i) 意思就是对于每一个sum[i],我们只需要找一个满足条件的最小的sum[j],然后我们就可以用一个单调队列来维护. #include<bits/stdc++.h> #define F(i,a…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29942    Accepted Submission(s): 10516 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44371    Accepted Submission(s): 16084 Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem…
Max Sum Plus Plus Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22262    Accepted Submission(s): 7484   Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. T…