HDU 1003 Max Sum
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 211310 Accepted Submission(s):
49611
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.
T(1<=T<=20) which means the number of test cases. Then T lines follow,
each line starts with a number N(1<=N<=100000), then N integers
followed(all the integers are between -1000 and 1000).
first line is "Case #:", # means the number of the test case. The second line
contains three integers, the Max Sum in the sequence, the start position of the
sub-sequence, the end position of the sub-sequence. If there are more than one
result, output the first one. Output a blank line between two cases.
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int main()
- {
- int t;
- int n;
- int a[];//存储序列
- int sum[];//存储以每个数为结尾的子序列和
- int s[];//存储开始位置
- int ans;//结束位置
- scanf("%d",&t);
- for(int i=;i<=t;i++){
- scanf("%d",&n);
- for(int i1=;i1<n;i1++){
- scanf("%d",&a[i1]);
- }
- ans=;
- sum[]=a[];
- s[]=;
- for(int j=;j<n;j++){
- if(sum[j-]>=){
- sum[j]=sum[j-]+a[j];
- s[j]=s[j-];
- }else{
- sum[j]=a[j];
- s[j]=j;
- }
- if(sum[ans]<sum[j])
- ans=j;
- }
- if(i<t){
- printf("Case %d:\n%d %d %d\n",i,sum[ans],s[ans]+,ans+);
- printf("\n");
- }else{
- printf("Case %d:\n%d %d %d\n",i,sum[ans],s[ans]+,ans+);
- }
- }
- return ;
- }
HDU 1003 Max Sum的更多相关文章
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- hdu 1003 Max Sum (DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
- HDU 1003 Max Sum【动态规划求最大子序列和详解 】
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- HDU 1003 Max Sum (动规)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- HDU 1003 Max Sum 解题报告
题目大意:求一串数字中,几个连续数字加起来最大值,并确定起始和最末的位置. 思路:这是一题DP题,但是可以用尺取法来做.我一开始不会,也是看了某大神的代码,然后有人告诉我这是尺取法,现在会了. //尺 ...
- HDU 1003 Max Sum(AC代码)
#include <stdio.h> int main(){ int i,t,j,n,x; int start,end,temp,max,sum; scanf("%d" ...
随机推荐
- 【ZOJ 3502】Contest
题 题意 n个问题,解决的顺序影响正确的概率,无论之前解决的问题是否答对,当前问题 j 答对概率为max{a[i][j]} (i为解决过的问题).求答对题目的最大期望和对应的答题顺序.T组测试,T ( ...
- bzoj3037 创世纪
两种解法: 一.树状DP /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring&g ...
- Model1模式的学生信息增删改查
Student.java package entity; public class Student { private int stuid; private String stuname; priva ...
- php中静态变量和静态方法
1,静态变量:所有对象共享的变量成为静态变量.静态变量类似于全局变量,不过全局变量破坏对象的封装性,因此其对应于面向过程:静态变量对应于面向对象. 2,全局变量,全局变量的使用实例如下,声明全局变量时 ...
- Color Space
色域(Color Space),又被称为色彩空间,它代表了一个色彩影像所能表现的色彩具体情况.我们经常用到的色彩空间主要有RGB.CMYK.Lab等,而RGB色彩 空间又有AdobeRGB.Apple ...
- tcp 重发 应用层重传
采用TCP时,应用层需要超时重传吗? 需要,原因如下: 1 tcp的超时控制不是你能设置的,所有的tcp超时都是用系统的时间设定,而且这个时间很长,超时的结果就是断开连接.和你应用要达到的目的显然差很 ...
- ModSecurity SQL注入攻击
ModSecurity是 一个入侵探测与阻止的引擎,它主要是用于Web应用程序所以也可以叫做Web应用程序防火墙.它可以作为Apache Web服务器的一个模块或单独的应用程序来运行.ModSecur ...
- udf提权方法和出现问题汇总
一.适用条件 1.目标系统是Windows(Win2000,XP,Win2003): 2.你已经拥有MYSQL的某个用户账号,此账号必须有对mysql的insert和delete权限以创建和抛弃函数( ...
- 安装TFS2008最终版(转载)
一.安装操作系统:windows server 2003 + Sp2具体步骤: 1.安装windows server 2003时选用工作组(默认为workgroup).由于在工作组环境中部署,因此使用 ...
- javascript单例模式的理解
javascript单例模式的理解 阅读目录 理解单例模式 使用代理实现单例模式 理解惰性单例 编写通用的惰性单例 单例模式使用场景 回到顶部 理解单例模式 单例模式的含义是: 保证一个类只有一个实例 ...