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. @RenderBody()和@RenderSection()

    强大的Razor引擎 一.Razor基础简介 Razor采用了cshtml后缀的文件名,截图如下: A. 版面布局 从图上看到,新的视图引擎已经没有了Site.Master这种MasterPage了, ...

  2. JSON未定义解决办法

    json官网:www.json.org json2.js地址:https://github.com/douglascrockford/JSON-js/blob/master/json2.js 引入解决 ...

  3. POJ 3670 , 3671 LIS

    题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列. 当然3671是只能升序,所以更简单一点. 然后就没有什么了,用二分的方法求LIS即可. ...

  4. Android Studio 完美修改应用包名

    我们平时新建项目有些朋友可能当时就是随意写的一个包名,然后在项目过程中, 又感觉这个包名不太好,所以就要对包名进行修改,根据我们正常的修改方式,是这样的. 在种情况是只能修改最外层的那个名称, 如果我 ...

  5. WEB网站常见受攻击方式及解决办法

    一个网站建立以后,如果不注意安全方面的问题,很容易被人攻击,下面就讨论一下几种漏洞情况和防止攻击的办法. 一.跨站脚本攻击(XSS) 跨站脚本攻击(XSS,Cross-site scripting)是 ...

  6. 关于Bufferedreader的功能扩写

    package cn.hncu.pattern.decorator.v1; import java.io.FileReader;import java.io.IOException; public c ...

  7. Android(java)学习笔记141:SQLiteDatabase的query方法参数分析

    public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] se ...

  8. 使用Netty进行Android与Server端通信实现文字发送接收与图片上传

    ANOTHER TITLE: Let’s use netty to achieve text send and receive and  image transfer to server based ...

  9. linux中的openoffice服务终止运行

    现象: 最近的linux中的openoffice服务进程运行一段时间后会自动停止,刚开始还以为忘了启动执行自启动脚本导致的.在连续出现前述情况后,开始查找应用程序崩溃的原因,首先查看linux服务器的 ...

  10. 11.14 noip模拟试题

      题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer ...