题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1003

题意

给出一个序列 要求找出一个和最大的子序列

思路

O(N)的做法 但是要标记 子序列的头部位置

如果输入全部是负数的话 应该输出是最小的负数和它的位置 而不是输出0 0 0

AC代码

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<list>
#include<stack>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5; int main()
{
int t;
cin >> t;
int count = 1;
while (t--)
{
int n;
scanf("%d", &n);
int num;
int flag = 1;
int tot = 0;
int ans = -1000;
int start = 0, end = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", &num);
tot += num; if (tot > ans)
{
ans = tot;
start = flag;
end = i;
}
if (tot < 0)
{
tot = 0;
flag = i + 1;
}
}
printf("Case %d:\n", count++);
printf("%d %d %d\n", ans, start, end);
if (t != 0)
cout << endl;
}
return 0;
}

HDU - 1003 Max Sum 【DP】的更多相关文章

  1. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  2. HDU 1003 Max Sum【动态规划求最大子序列和详解 】

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

  3. hdu 1003 Max sum(简单DP)

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

  4. HDU 1003 Max Sum(DP)

    点我看题目 题意 : 就是让你从一个数列中找连续的数字要求他们的和最大. 思路 : 往前加然后再判断一下就行. #include <iostream> #include<stdio. ...

  5. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  6. hdu 1003 Max Sum (DP)

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

  7. hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

  8. 杭电1003 Max Sum 【连续子序列求最大和】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...

  9. HDU 1003 Max Sum && HDU 1231 最大连续子序列 (DP)

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

随机推荐

  1. js:获得时间

    <script type="text/javascript"> function bodyLoad() { var dateTime = new Date(); var ...

  2. 【转】GitHub入门详细讲解

    第一:请登录https://windows.github.com/ 下载您需要的安装软件,进行安装.安装后桌面有:GitHub 和 Git Shell 第二: 申请一个帐号https://github ...

  3. ClassLibary和WPF User Control LIbary和WPF Custom Control Libary的异同

    说来惭愧,接触WPF这么长时间了,今天在写自定义控件时遇到一个问题:运行界面中并没有显示自定义控件,经调试发现原来没有加载Themes中的Generic.xaml. 可是为什么在其他solution中 ...

  4. 【CODEFORCES】 A. Initial Bet

    A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. C# Html Agility Pack

    using System; using HtmlAgilityPack; using System.IO; using System.Text; using System.Text.RegularEx ...

  6. Maven环境下搭建SSH框架

    © 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Maven:3.3.9 Struts2:2.5.10 Spring:4.3.8.RELEASE Hibernate:5.1.7.Fina ...

  7. Atitit.mysql 5.0 5.5  5.6 5.7  新特性 新功能

    Atitit.mysql 5.0 5.5  5.6 5.7  新特性 新功能 1. MySQL  5.6    5 大新特性1 1.1. 优化器的改进1 1.2. InnoDB 改进1 1.3. 使用 ...

  8. HTML5 2D平台游戏开发#7Camera

    在庞大的游戏世界中,玩家不能一览地图全貌,而是只能看到其中一部分,并一步步探索,这时就要用到一种技术来显示局部的地图,游戏术语称为摄像机(Camera).下面两张图中的白色矩形框表示了Camera的作 ...

  9. Mysql主从配置笔记

    1.配置my.cnf无效,且mysql进程无法启动 从5.1.7版本开始,不再支持my.cnf直接配置master-host等主从相关配置选项(依然支持replicate-do-db).改为使用 CH ...

  10. Mysql:1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'错误解决

    select distinct b.sale_count from product_sale b where b.pro_id in (select a.pro_id from product a L ...