hdu1003 Max Sum(经典dp )
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include <cstdio>
int main()
{
int T,k, R, L, Max, sum, t, total=, n;
scanf("%d", &T);
while(T--)
{
sum = Max =-; //足够小就好
scanf("%d", &n);
for(int i=; i<=n; i++)
{
scanf("%d", &t);
if (sum<)
{
sum = t, k = i;
}
else
sum += t;
if (Max < sum) Max = sum, L = k, R = i; //L R分别为初始和结束位置
}
printf("Case %d:\n", total++);
printf("%d %d %d\n", Max, L, R );
if (T) printf("\n");
}
return ;
}
#include<iostream>
using namespace std;
int a[],b[];
int main()
{
int n,T,s,t,max,total,k=;
cin>>T;
while(T--)
{
cin>>n;
for(int i=; i<=n; i++)
cin>>a[i];
b[]=a[];
for(int i=; i<=n; i++)
{
if(b[i-]<)
b[i]=a[i];
else
b[i]=b[i-]+a[i];
}
max=b[];
s=;
for(int i=; i<=n; i++)
{
if(b[i]>max)
{
max=b[i];
s=i;
}
}
t=s;
total=;
for(int i=s; i>=; i--)
{
total+=a[i];
if(total==max) t=i;
}
cout<<"Case "<<k++<<":"<<endl;
cout<<max<<" "<<t<<" "<<s<<endl;
if(T) cout<<endl;
}
}
hdu1003 Max Sum(经典dp )的更多相关文章
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
- ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)
Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...
- 解题报告:hdu1003 Max Sum - 最大连续区间和 - 计算开头和结尾
2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare ...
- Max Sum (dp)
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. F ...
- 最大子序列和——HDU-1003 Max Sum
题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义dp[i]表示以a[i]为结尾的子序列的和的最大值,因而最大 ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- HDU-1003 Max Sum(动态规划,最长字段和问题)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU1003 Max Sum(求最大字段和)
事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 -------------- ...
随机推荐
- How to distribute your own Android library through jCenter and Maven Central from Android Studio
In Android Studio, if you wish to include any library to your application. You could just simply add ...
- 常用Application Server
综述,我们这里列出的application server应用服务器,主要是对servlet和JSP提供了良好的支持; [resin] [Tomcat] [jboss] community.jboss. ...
- javaweb开发过程中的地址写法
凡是要表示web资源的地址,比如浏览器地址栏中,都是 /凡是要表示硬盘地址, 都是 \ public class ServletDemo1 extends HttpServlet { //实际开发过 ...
- 项目经历——EasyUI的检索和更新操作
什么事都耐不住“磨”?! 比如一个让人很头疼的问题,对于项目中所用到的EasyUI框架就是一个很明显的感受.项目使用的EasyUI框架,自身封装好的样式使得开发者不用考虑具体的div和css样式了,但 ...
- js~this的陷阱
在JS中,当前对象一般用this表示,在jquery中,当前的对象是用$(this)表示,这些都是最基础的知识,没什么可说的,但我要说的是,当this出现在某个深度时,它的含义你自己要清楚,它是指离当 ...
- android图片缓存框架Android-Universal-Image-Loader
http://blog.csdn.net/king_is_everyone/article/details/34107081 最近跟同学们做了一个创业项目,其实跟以前做项目不同,以前大多数都是做web ...
- Java 7之多线程- Semaphore--转载
Semaphore用于保存当前可用许可的数量.是通过共享锁实现的.根据共享锁的获取原则,Semaphore分为"公平信号量"和"非公平信号量". "公 ...
- [转] FDA批准首个莫米松植入式给药系统用于治疗慢性鼻窦炎
from: http://www.qqyy.com/jibing/erbihouke/111020/3fd2f.html http://www.chemdrug.com/news/231/5/2494 ...
- php 之 post json 数据
原文链接 http://www.jb51.net/article/27312.htm 最近用到python 与PHP交互,phthon把json数据post给PHP,但在PHP里面$_post获取不到 ...
- python与数值计算环境搭建
数值计算的编程的软件很多种,也见过一些编程绘图软件的对比. 利用Python进行数值计算,需要用到numpy(矩阵) ,scipy(公式符号), matplotlib(绘图)这些工具包. 1.Linu ...