题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int t,n,k,x=,a[],dp[],flag=;
int main()
{
scanf("%d",&t);
while(t--)
{
if(flag++!=) printf("\n");
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
int max=-;
memset(dp,,sizeof(dp));
dp[]=a[];
for(int i=; i<=n; i++)
dp[i]=dp[i-]+a[i]>a[i] ? dp[i-]+a[i] : a[i];
for(int i=; i<=n; i++)
{
if(dp[i]>max)
{
max=dp[i];
k=i;
}
}
int sum=,p=;
for(int i=k; i>=; i--)
{
sum+=a[i];
if(sum==max) p=i;
}
printf("Case %d:\n%d %d %d\n",++x,max,p,k);
}
return ;
}

hdu1003 dp的更多相关文章

  1. hdu1003 dp(最大子段和)

    题意:给出一列数,求其中的最大子段和以及该子段的开头和结尾位置. 因为刚学过DP没几天,所以还会这题,我开了一个 dp[100002][2],其中 dp[i][0] 记录以 i 为结尾的最大子段的和, ...

  2. HDU1003 dp 动态规划解析

    Input The first line of the input contains an integer T(1<=T<=20) which means the number of te ...

  3. hdu1003 1024 Max Sum&Max Sum Plus Plus【基础dp】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4302208.html   ---by 墨染之樱花 dp是竞赛中常见的问题,也是我的弱项orz, ...

  4. HDU1003 简单DP

    Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the ...

  5. dp经典问题-最大连续子序列和 hdu1003

    题目描述: 这道题我先后做过三遍,结果每一遍都没有做出来.今天再仔仔细细的研究了一下,才发现用动态规划更好理解. 关于求最大连续子序列和的博文转载如下:https://www.cnblogs.com/ ...

  6. Max Sum—hdu1003(简单DP) 标签: dp 2016-05-05 20:51 92人阅读 评论(0)

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

  7. HDU1003 最大子段和 线性dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)  ...

  8. HDU1003:Max Sum(简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题意一目了然就不说了,算法是从左往右扫,一个暂时保存结果的值,如果区间结果<0,那么就更改左右 ...

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

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

随机推荐

  1. ZipArchive和SSZipArchive使用详解

    一.SSZipArchive 1.简介 SSZipArchive是iOS和Mac上一个简单实用的压缩和解压插件.用途包括:1.解压zip文件:2.解压密码保护的ZIP文件:3.创建新的zip文件:4. ...

  2. zookeeper windows 入门安装和测试

    一.序言       以下是我对zookeeper 的一些理解:       zookeeper 作为一个服务注册信息存储的管理工具,好吧,这样说得很抽象,我们举个“栗子”. 栗子1号: 假设我是一家 ...

  3. oracle触发器加条件判断

    oracle触发器加条件判断,如果某个字段,isnode=0,那么不执行下面的方法,数据如下: create or replace trigger tr_basestation_insert_emp ...

  4. Android 6.0的运行时权限

    原文  http://droidyue.com/blog/2016/01/17/understanding-marshmallow-runtime-permission/ 主题 安卓开发   Andr ...

  5. 【编程题目】在 O(1)时间内删除链表结点

    60.在 O(1)时间内删除链表结点(链表.算法).题目:给定链表的头指针和一个结点指针,在 O(1)时间删除该结点.链表结点的定义如下:struct ListNode{int m_nKey;List ...

  6. VS中新建类

    通常我们在VS中添加类,比如要声明一个car的类 我们通常在新建的时候会写成CCar,虽然新建出来的文件的名词是car,但是我们使用这个类来声明一个类的时候, 是CCar car; 如果新建类写成Ca ...

  7. CABasicAnimation animationWithKeyPath 一些规定的值

    CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...

  8. cmd for备忘

    =============参数 /d (参数只能显示当前目录下的目录名字)=================== rem 显示d:\work\目录下与*.txt相匹配的文件(如果报错就%i-> ...

  9. 字符匹配算法之Boyer-Moore算法

    Boyer-Moore算法的精华是从后向前,取好后缀与坏后缀中的最大移动位移动搜索词,以达到最快速检索的效果. 详情参考:http://www.ruanyifeng.com/blog/2013/05/ ...

  10. Android 更改字体

    1. 将字体ttf文件放在assets目录下 2. 使用: Typeface mTypeFaceLight = Typeface.createFromAsset(context.getAssets() ...