Input
The first line of the input contains an integer 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).
 
Output
For each test case, you should output two lines. The 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>
using namespace std;
int main()
{
 int N;
 cin>>N;
 int i,count=1;
 while(N--)
 {
  int n;
  int now,before,sum,x,y,z;
  cin>>n;
  for(i=1;i<=n;i++)
  {
   cin>>now;
   if(i==1)
   {
    sum=before=now;//sum保存最大和,before保存当前的和 ,x表示before的起始位置,y,z表示sum的始末位置
    x=y=z=i;
   }
   else
   {
    if(now+before>now)
     before=before+now;
    else
    {
     befor=now;
     x=i;//预存位置要重置
    }
   }
   if(before>sum)
   {
    sum=before;
    y=x;
    z=i;
   }

}
  cout<<"Case "<<count++<<":"<<endl<<sum<<" "<<y<<" "<<z<<endl;
  if(N>=1)
   cout<<endl;
 }
 return 0;
}

HDU1003 dp 动态规划解析的更多相关文章

  1. Day 5 笔记 dp动态规划

    Day 5 笔记 dp动态规划 一.动态规划的基本思路 就是用一些子状态来算出全局状态. 特点: 无后效性--狗熊掰棒子,所以滚动什么的最好了 可以分解性--每个大的状态可以分解成较小的步骤完成 dp ...

  2. (转)dp动态规划分类详解

    dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...

  3. 【模板整合计划】DP动态规划

    [模板整合计划]DP动态规划 一:[背包] 1.[01背包] 采药 \([P1048]\) #include<algorithm> #include<cstdio> int T ...

  4. DP动态规划学习笔记——高级篇上

    说了要肝的怎么能咕咕咕呢? 不了解DP或者想从基础开始学习DP的请移步上一篇博客:DP动态规划学习笔记 这一篇博客我们将分为上中下三篇(这样就不用咕咕咕了...),上篇是较难一些树形DP,中篇则是数位 ...

  5. 树形DP——动态规划与数据结构的结合,在树上做DP

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是算法与数据结构的第15篇,也是动态规划系列的第4篇. 之前的几篇文章当中一直在聊背包问题,不知道大家有没有觉得有些腻味了.虽然经典的文 ...

  6. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  7. 摆花 (DP动态规划)

    2012_p3 摆花 (flower.cpp/c/pas) 时间限制: 1 Sec  内存限制: 128 MB提交: 17  解决: 10[提交][状态][讨论版][命题人:外部导入] 题目描述 3. ...

  8. [原]POJ1141 Brackets Sequence (dp动态规划,递归)

    本文出自:http://blog.csdn.net/svitter 原题:http://poj.org/problem?id=1141 题意:输出添加括号最少,并且使其匹配的串. 题解: dp [ i ...

  9. DP动态规划练习

    先来看一下经典的背包问题吧 http://www.cnblogs.com/Kalix/p/7617856.html  01背包问题 https://www.cnblogs.com/Kalix/p/76 ...

随机推荐

  1. 使用bash判断PATH中是否存在某个路径

    在source设置环境变量的时候,有些时候可能会设置两次,导致增加系统的路径搜索时间,或者让自己看环境变量的时候搞得怪不爽的. 为了解决这个问题,我们可以在设置相应的环境变量之前,先判断一下是否已经设 ...

  2. contentProvider模板

    package com.example.qunzheng.todolist.provider; import android.content.ContentProvider; import andro ...

  3. oc中的类学习笔记1

    1.oc中的类和构造方法 NSAutoreleasePool * pool =[[NSAutoreleasePool alloc] init]; NSAutoreleasePool是一个类,alloc ...

  4. php笔记04:get/post请求有两种主要方式

    get/post的区别有哪些? 1. 安全性get请求的数据会显示在地址栏上,post请求的数据,放在http协议的消息体中   2. 从可以提交的数据大小来看:   http协议本身并没有限制数据大 ...

  5. ASP.NET 开发人员应该知道的8个网站

    1.CodeProject http://www.codeproject.com/ 2.DotNetNuke 3.4GuysFromRolla 4.DevSource 5.DevX http://ww ...

  6. VS的一部分快捷键

    快捷键                                         功能CTRL + SHIFT + B                        生成解决方案CTRL + F ...

  7. angularjs填写表单

    https://scotch.io/tutorials/handling-checkboxes-and-radio-buttons-in-angular-forms <!DOCTYPE html ...

  8. JavaScript平常会跳的坑系列(一)

    function Foo() { //定义foo函数 getName = function () { console.log('1');}; console.log(this); return thi ...

  9. js 如何创建一个对象

    有两种简单方法可以创建一个空对象: var obj = new Object(); 和: var obj = {}; 这两种方法在语义上是相同的.第二种更方便的方法叫作“对象字面量(object li ...

  10. Git 常用配置和使用

    Git:是一个分布式的源代码管理工具,Linux内核的代码就是用Git管理的所以它很强,也很快, 和 Vss/SVN比起来 本地Git初始化配置及其使用: 1. 初始化本地Git库:打开Git Bas ...