HDU 1003 MAXSUM(最大子序列和)
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
int t,n;
int i,j,k=;
int Max,sum,x,y,l,d;
scanf("%d",&t);
while(t--)
{
Max=sum=-INF;
scanf("%d",&n);
for(i=; i<=n; i++)
{
scanf("%d",&d);
if(sum+d<d)
sum=d,l=i;
else
sum+=d;
if(Max<sum)
{
x=l;
y=i;
Max=sum;
}
}
if(k)
printf("\n");
printf("Case %d:\n",++k);
printf("%d %d %d\n",Max,x,y);
}
return ;
}
HDU 1003 MAXSUM(最大子序列和)的更多相关文章
- HDU 1003 maxsum
#include<iostream> #include<vector> using namespace std; typedef struct { int maxsum; in ...
- 【ToReadList】六种姿势拿下连续子序列最大和问题,附伪代码(以HDU 1003 1231为例)(转载)
问题描述: 连续子序列最大和,其实就是求一个序列中连续的子序列中元素和最大的那个. 比如例如给定序列: { -2, 11, -4, 13, -5, -2 } 其最大连续子序列为{ 11, ...
- hdu 1003 hdu 1231 最大连续子序列【dp】
HDU1003 HDU1231 题意自明.可能是真的进步了点,记得刚开始研究这个问题时还想了好长时间,hdu 1231还手推了很长时间,今天重新写干净利落就AC了. #include<iostr ...
- HDU 1231 最大连续子序列 --- 入门DP
HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)
C - 最大连续子序列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- dp 动态规划 hdu 1003 1087
动态规划就是寻找最优解的过程 最重要的是找到关系式 hdu 1003 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目大意:求最大字序列和, ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
随机推荐
- 数据库存储 datetime,时差问题
var offset = moment().utcOffset(); var localText = moment.utc(datetime from database).utcOffset(offs ...
- shell中颜色的设置
linux启动后环境变量加载的顺序为:etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc] 想 ...
- tomcat配置的环境变量catalina.home和catalina.base 区别
本篇文章原创地址为:http://blog.csdn.net/you23hai45/article/details/27726147 这两个属性仅在你需要安装多个Tomcat实例而不想安装多个软件备份 ...
- maven构建ssh工程
1.1 需求 在web工程的基础上实现ssh工程的创建,规范依赖管理. 1.2 数据库环境 使用之前学习hibernate创建的数据库: 1.3 创建父工程 选择创建Maven Project ...
- Ubuntu 16.04 更换阿里源
vim /etc/apt/source.list deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by s ...
- andorid 菜单 进度条
activity_ui2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- iOS.-.cxx_destruct
-.cxx_destruct 方法: 该方法是由编译器生成的方法. 1. “ARC actually creates a -.cxx_destruct method to handle freeing ...
- (O)JS高阶函数应用——函数节流
在一些函数需被频繁调用的场景,如:window.onresize.mousemove.scroll滚动事件.上传进度等等,操作频繁导致性能消耗过高,而造成浏览器卡顿现象,我们可以通过函数节流的方式解决 ...
- git报“commiter email "root@localhost.localdomain"does not match your user account”
首先检查账户邮箱配置是否正确,检查方法: git config --list 发现邮箱及帐号配置正确,但是git push时仍然报如题错误: 原因:git执行add.commit 时已经记录下了做了该 ...
- You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed问题解决
https://zeroturnaround.com/forums/topic/jrebel-reports-more-than-one-version-of-org-apache-commons-l ...