/*求最大字段和,d[i]表示已 i 结尾(字段和中包含 i )在 a[1..i] 上的最大和,d[i]=(d[i-1]+a[i]>a[i])?d[i-1]+a[i]:a[i];max = {d[i],1<=i<=n} ;至于起点和终点,要各定义一个变量去跟踪,尤其是起点*/

#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"ctype.h"
#include"cmath"
#define mx 100005
#define inf -32766
using namespace std;
int dp[mx];
int a[mx];
int n;
int main()
{
int t,i;
cin>>t;
int count1=0;
while(t--)
{
count1++;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
int cur=0,sx=0,ey=0,mxsub=dp[0]=a[0];
for(i=1;i<n;i++)
{
if(dp[i-1]+a[i]>=a[i])//因为题目要求的是若有多个解,取第一个,故这里要加上等号
{
dp[i]=dp[i-1]+a[i];
}
else
{
dp[i]=a[i];
cur=i;//记录起点的变化,当最大子序列的和改变时,起点有可能随着改变
}
if(dp[i]>mxsub)
{
mxsub=dp[i];
ey=i;
sx=cur;
}
}
cout<<"Case "<<count1<<":"<<endl;
cout<<mxsub<<' '<<sx+1<<' '<<ey+1<<endl;
if(t) cout<<endl;//题中用的是between,所以最后一个输出后面没有空行
}
return 0;
}

hdu-acm steps Max sum的更多相关文章

  1. HDU 1024:Max Sum Plus Plus(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Problem Description Now I think you ...

  2. HDU 1003:Max Sum(DP,连续子段和)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  3. HDU 1024:Max Sum Plus Plus(DP,最大m子段和)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1024:Max Sum Plus Plus 经典动态规划之最大M子段和

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU 1003:Max Sum

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  6. hdu acm steps Big Event in HDU

    上网搜了一下这道题的解法,主要有两个方法,一种是采用母函数的方法,一种是采用0/1背包的方法. 先说一下母函数,即生成函数,做个比喻,母函数就是一个多项式前面的系数的一个整体的集合,而子函数就是这个多 ...

  7. HDU 1024 A - Max Sum Plus Plus DP + 滚动数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...

  8. 【HDU 1003】 Max Sum

    题 题意 需要在o(n)时间内,求最大连续的子序列的和,及其起点和终点. 分析 一种方法是一边读,一边维护最小的前缀和 s[i] ,然后不断更新 ans = max(ans,s[j] - s[i]), ...

  9. HDU 1024 DP Max Sum Plus Plus

    题意:本题的大致意思为给定一个数组,求其分成m个不相交子段和最大值的问题. kuangbin专题. dp[i][j]=Max(dp[i][j-1]+a[j] , max( dp[i-1][k] ) + ...

随机推荐

  1. WPF 打印控件 无弹框打印。

    WPF中打印用到了 PrintDialog类. 其中设置打印属性的是PrintTicket,管理打印机的是PrintQueue. 实例如下: public class PrintDialogHelpe ...

  2. mybatis配置文件xml中插入新数据

    初用mybatis,发现很好的一个操作数据库的框架,里面有一些小技巧,挺简单,很实用,记录一下: mybatis的插入语句: <insert id="insertAsset" ...

  3. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

  4. WebStorm设置字体和颜色

    新建Scheme + 修改字体 ctrl+alt+s打开Settings界面,Editor > Colors&Fonts > Font. Default scheme是亮色调,但我 ...

  5. Myeclipse中把java代码导成UML类图

    Myeclipse中把java代码导成UML类图 1.右键点击项目名称,选择New-------àUML2 Model 2.给类图命名 3.导成类图 1)如果要把整个项目导成类图,则把整个项目拖到类图 ...

  6. git branch -D 大写的D 删除分支

    今天删除本地分支 git branch -d XXX 提示:  the branch  XXX is not fully merged 原因:XXX分支有没有合并到当前分支的内容 解决方法:使用大写的 ...

  7. vijos 1037 ***

    链接:点我 #include <cstdio> #include <cstring> #include <algorithm> #include <iostr ...

  8. HDU 4258 Covered Walkway 斜率优化DP

    Covered Walkway Problem Description   Your university wants to build a new walkway, and they want at ...

  9. Unrecognized Windows Sockets error: 0: JVM_Bind

    Unrecognized Windows Sockets error: 0: JVM_Bind [转帖]今天很是奇怪,在运行服务器端的时候,经常遇到这个异常: java.net.SocketExcep ...

  10. Loadrunner请求自定义的http(json)文件and参数化

    Loadrunner请求自定义的http(json)文件and参数化      研究啦好些天这个东西啦 终于出来答案啦 嘿嘿 给大家分享一下 : 请求自定义的http文件用函数:web_custom_ ...