【HDOJ】1003 Max Sum
最开始使用递归DP解,stack overflow。化简了一些,复杂度为O(n)就过了。
#include <stdio.h>
int main() {
int case_n, n;
int i, j, tmp;
int beg, end, sum, max_sum;
int number;
scanf("%d", &case_n);
for (i=; i<=case_n; i++) {
scanf("%d", &n);
beg = ;
tmp = ;
end = ;
sum = ;
max_sum = -;
for (j=; j<n; j++) {
scanf("%d", &number);
sum += number;
if (sum > max_sum) {
max_sum = sum;
beg = tmp;
end = j;
}
if (sum < ) {
sum = ;
tmp = j+;
}
}
printf("Case %d:\n", i);
printf("%d %d %d\n", max_sum, beg+, end+);
if (i != case_n)
printf("\n");
}
return ;
}
【HDOJ】1003 Max Sum的更多相关文章
- 【HDOJ】1244 Max Sum Plus Plus Plus
这题目一直wa,原来是因为我把JUDGE写错了,对拍了一下午都没检查出来.水DP啊. #include <cstdio> #include <cstring> #include ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- 【leetcode】363. Max Sum of Rectangle No Larger Than K
题目描述: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the ma ...
- 【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum- ...
- 【HDOJ】3473 Minimum Sum
划分树解.主席树解MLE. /* 3473 */ #include <iostream> #include <sstream> #include <string> ...
- 【HDOJ】P2058 The sum problem
题意很简单就是给你一个N和M,让你求在1-N的那些个子序列的值等于M 首先暴力法不解释,简单超时 再仔细想一想可以想到因为1-N是一个等差数列,可以运用我们曾经学过的只是来解决 假设开始的位置为s,结 ...
- 【LeetCode】813. Largest Sum of Averages 解题报告(Python)
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 1003 Max Sum (DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- Git的安装以及注册账号等操作
1.安装Git-2.5.1-64-bit.exe 一直下一步直至完成 2.注册github账号 官网地址:https://github.com/github 3.找到一个按钮“New Reposit ...
- 11_Servlet的一些细节知识点
[Servlet的细节知识点1-----一个Servlet映射到多个URL] 同一个Servlet可以被映射到多个URL上,即多个<servlet-mapping>元素的<servl ...
- Python爬虫第一集
import urllib2 response = urllib2.urlopen("http://www.baidu.com") print response.read() 简单 ...
- C++中map用法
/************************************************************************** Map的特点: 1.存储Key-value对* ...
- Wix installer: suppressing the License Dialog
Reference Link: http://blog.robseder.com/2014/02/20/more-on-wix-and-suppressing-the-license-dialog/ ...
- OpenJudge 2754 八皇后
1.链接地址: http://bailian.openjudge.cn/practice/2754 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 会下国际象棋的人都很清楚: ...
- 第43条:返回零长度的数组或者集合,而不是null
private final List<Cheese> cheesesInStock = ...; public Cheese[] getCheese() { if(cheesesInSto ...
- CentOS7 查看ip
查看内网:ip addr 查看公网:curl members.3322.org/dyndns/getip
- 通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(五)
这一节,用个简单的例子来调用下之前生成的service.ane 首先建一个flex手机项目 然后在构建路径中把ane引进来 可以看到此ane支持Android平台. serviceMobile.mxm ...
- TweenMax动画库学习(三)
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) ...