Max Sum

Time Limit: 1000ms
Memory Limit: 32768KB
 
This problem will be judged on HDU. Original ID: 1003
64-bit integer IO format: %I64d      Java class name: Main
 
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

 

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

 

Sample Input

2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
 

Sample Output

Case 1:
14 1 4 Case 2:
7 1 6 解题:dp入门题!弱菜的成长之路啊!
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
int dp[],num[];
int main(){
int kase,i,index,ans,n,k = ;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(i = ; i <= n; i++)
scanf("%d",dp+i);
num[] = ;
ans = dp[index = ];
for(i = ; i <= n; i++){
if(dp[i] <= dp[i-]+dp[i]){
dp[i] = dp[i-]+dp[i];
num[i] = num[i-]+;
}else num[i] = ;
if(ans < dp[i]) ans = dp[index = i];
}
printf("Case %d:\n",k++);
printf("%d %d %d\n",ans,index-num[index],index);
if(kase) putchar('\n');
}
return ;
}

最新文章

  1. 阿里云推送SDK在某些机型(某米为主)下崩溃问题的解决方法
  2. 初学RunLoop
  3. LUA类
  4. 深入浅出Mybatis系列(七)---mapper映射文件配置之insert、update、delete
  5. ASP.NET DAY1
  6. 通过PowerShell发送TCP请求
  7. submit回车提交影响
  8. 【windows核心编程】一个API拦截的例子
  9. bnuoj 4187 GCC (数论)
  10. hibernate实体的几种状态:
  11. 什么是CTS、CLS和CLR
  12. cocos2dx3.2 异步载入和动态载入
  13. [WPF]不规则窗体的实现
  14. java线程池ThreadPool
  15. linux_Nginx日志
  16. Python第三方库的安装方法总结
  17. [转]使用jenkins实现持续集成
  18. IIS异常:CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问
  19. 51Nod1123 X^A Mod B 数论 中国剩余定理 原根 BSGS
  20. function前加运算符实现立即执行函数

热门文章

  1. [转]Ioc容器Autofac
  2. 阻塞 io 非阻塞 io 学习笔记
  3. SQL注入原理与解决方法代码示例
  4. mongodb 上限集合
  5. Verilog 参数化设计
  6. Notepad++设计Tab制表符为4个空格
  7. Redis学习笔记(一)五种数据类型
  8. ubuntu 16.0 利用ant编译 hadoop-eclipse-plugins2.6.0
  9. ConCurrent in Practice小记 (4)
  10. 分布式锁----浅析redis实现