hdu1003 dp
题目链接: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的更多相关文章
- hdu1003 dp(最大子段和)
题意:给出一列数,求其中的最大子段和以及该子段的开头和结尾位置. 因为刚学过DP没几天,所以还会这题,我开了一个 dp[100002][2],其中 dp[i][0] 记录以 i 为结尾的最大子段的和, ...
- HDU1003 dp 动态规划解析
Input The first line of the input contains an integer T(1<=T<=20) which means the number of te ...
- hdu1003 1024 Max Sum&Max Sum Plus Plus【基础dp】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4302208.html ---by 墨染之樱花 dp是竞赛中常见的问题,也是我的弱项orz, ...
- HDU1003 简单DP
Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the ...
- dp经典问题-最大连续子序列和 hdu1003
题目描述: 这道题我先后做过三遍,结果每一遍都没有做出来.今天再仔仔细细的研究了一下,才发现用动态规划更好理解. 关于求最大连续子序列和的博文转载如下:https://www.cnblogs.com/ ...
- 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 ...
- HDU1003 最大子段和 线性dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others) ...
- HDU1003:Max Sum(简单dp)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题意一目了然就不说了,算法是从左往右扫,一个暂时保存结果的值,如果区间结果<0,那么就更改左右 ...
- 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)
最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...
随机推荐
- codeforces 540B.School Marks 解题报告
题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test ...
- 【leetcode】Binary Tree Postorder Traversal (hard) ☆
二叉树的后序遍历 用标记右子树vector的方法 vector<int> postorderTraversal(TreeNode *root) { vector<int> an ...
- IOS - Objective-C NSArray和NSMutableArray的详解 使用
原文地址:http://blog.csdn.net/totogo2010/article/details/7729377 Objective-C的数组比C++,Java的数组强大在于,NSArray保 ...
- 9.27js拓展、bootstrap菜鸟教程
js(点击挂上 与 点击移除) <div id="dd" style="width:200px; height:200px; background-color:#6 ...
- iOS系类教程之用instruments来检验你的app
比较了好多关于instruments 还是发现老外写的比较牛逼.于是果断翻译过来.有能力的的可以去看英文原版,鼓励大家看原版资料远离二手教程.这里是原文 入门 为了节省大家的时间,提供一个演示的D ...
- ReactNative环境配置
参考链接 Windows系统安装React Native环境 windows下React Native Android 环境搭建 在Windows下搭建React Native Android开发环境 ...
- VCC、VDD、VSS、 VEE 和VPP的区别
在电子电路中,常可以看到VCC.VDD和VSS三种不同的符号,它们有什么区别呢? 一.解释 VCC:C=circuit 表示电路的意思, 即接入电路的电压: VDD:D=device 表示器件的意思, ...
- Java -- 找不到或无法加载主类
原文:http://wenku.baidu.com/link?url=5nS1GEaePn-hmtAg6xXdJvtt9Z89JQsakhqSv8fambaJY2t9nKPtf3hXFpjW-BtD9 ...
- Java集合源码学习(一)集合框架概览
>>集合框架 Java集合框架包含了大部分Java开发中用到的数据结构,主要包括List列表.Set集合.Map映射.迭代器(Iterator.Enumeration).工具类(Array ...
- 【131202】SQL
SELECT TOP 2 * FROM Persons SELECT *FROM PersonsWHERE ROWNUM <= 5 SELECT * FROM Persons WHERE C ...